FAQ
Authentication troubleshooting and an error code reference.
Authentication
How do I troubleshoot a 401?
Check in order:
- Is the request header
Authorization: Bearer sk-tp-...? Note the single space betweenBearerand the key. - Was the key copied in full, and has it maybe expired and been recreated? The plaintext is shown only once at creation and can't be recovered if lost. Create a new key in the Console and revoke the old one.
- Has the key or any of its parents been revoked? Revoking a parent key invalidates its entire subtree.
- Is the account status normal (can you sign in to the Console)?
All my sub-keys suddenly stopped working?
Walk up the parent chain: if any parent has been revoked, the entire subtree is rejected on calls (401). To recover, create a new key under a valid parent key.
Why isn't there an X-Cost-Yuan header in streaming responses?
That header is returned only in non-streaming responses. For streaming calls, parse the final usage chunk to calculate the cost yourself, or check the charge in the billing ledger.
Error codes
Error response body format:
When parameter validation fails, message is an array of strings. Errors returned by the upstream model service are passed through verbatim (status code and response body unchanged).
| Status code | Scenario | Common causes |
|---|---|---|
| 400 | Invalid request parameters | model doesn't exist or isn't available, messages is empty, field validation failed |
| 401 | Authentication failed | missing Bearer, invalid or revoked key, account unavailable |
| 402 | Insufficient balance or quota | insufficient account balance, a level in the key chain has exhausted its quota |
| 403 | Insufficient permission | some operations require identity verification first |
| 404 | Resource not found | model, key, or order not found |
| 409 | State conflict | creating a key / initiating a top-up before identity verification, creating a sub-key under a revoked parent |
| 504 | Upstream timeout | upstream gateway timed out (300 seconds by default) |