Errors. One shape, a type you can switch on.
Failed requests return a non-2xx status and a JSON body in the same shape every time.
Error shape
{
"type": "error",
"error": {
"type": "insufficient_credits_error",
"message": "..."
}
}Branch on error.type, not on the message. Messages are for people and may change.
Error types
| Field | Description |
|---|---|
invalid_request_error | The request is malformed or a value is invalid: not multipart, a bad charts array, an unknown difficulty, model or rerank, an unreadable or too-long song, or asking for the result before the job has succeeded. |
authentication_error | The API key is missing, malformed or revoked. |
insufficient_credits_error | Your balance is lower than the cost of the request. |
permission_error | The key is valid, but your Discord account no longer has access to the closed beta. |
not_found_error | No such chart job on your account, an unknown endpoint, or a result that has expired. |
request_too_large | The audio file is over the 40 MB limit. |
rate_limit_error | You already have a chart in progress. Wait for it to finish or cancel it. |
api_error | Something went wrong on our side. Try again later. |
origin_unavailable_error | The chart service is offline or not reachable right now. Try again later. |
An origin_unavailable_error is a good candidate for a retry with backoff. For insufficient_credits_error, see Credits and limits.
The request-id header
Every response, successful or not, carries a request-id header such as req_.... Log it. If you ask for help with a failed call, include it.
curl -i https://api.prisx.tech/v1/balance
HTTP/2 401
request-id: req_...
content-type: application/jsonHandling errors
import os
import requests
r = requests.get(
"https://api.prisx.tech/v1/balance",
headers={"x-api-key": os.environ["PRISX_API_KEY"]},
)
if not r.ok:
err = r.json()["error"]
print(r.status_code, err["type"], err["message"], r.headers.get("request-id"))