Authentication
1. Overview
Authentication is used to obtain and manage access tokens for protected API endpoints.
2. Authentication
2.1 Get an API key
2.2 Generate an access token with an API key
Request
- Method: POST
- Path:
https://api.nuwaai.com/web/apiKey/auth - Body:
{
"secretKey": "{apikey}"
}
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| apikey | String | Yes | Key generated from the API key |
Response
{
"code": {code},
"msg": {message},
"data": {data}
}
| Name | Type | Required | Description |
|---|---|---|---|
| code | int | Yes | Response code: 0 means OK; other values indicate an error. |
| message | String | No | Error details when the response code is not 0. |
| data | String | Yes | The returned access token when the response code is 0. |
示例
const secretKey = 'sk-jqZ-gBPcRCG1nLpaenmS1gew7rcCkIs-NUWSPzpd3DeWYxobM_CHm-uPTCa8gDPv';
fetch('https://api.nuwaai.com/web/apiKey/auth', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
secretKey: secretKey,
}),
})
.then(res => res.json())
.then(data => {
if (data.code === 0) {
console.log('token:', data.data);
localStorage.setItem('token', data.data);
} else {
console.error('Request failed:', data.msg);
}
})
.catch(error => {
console.error('Request error:', error);
});