Error Codes

When calling the MaiToken API, you can diagnose issues using HTTP status codes and the business error codes returned in the response body:

  • HTTP Status Code indicates the overall processing result of the request.
  • Business Error Code is located in the error.code field of the response body, explaining the specific cause of the error.
  • Error Type is located in the error.type field, facilitating unified identification and handling of similar exceptions by applications.

It is recommended to troubleshoot based primarily on business error codes, and adjust requests according to the error message and suggested solutions. If the issue persists, please provide technical support with the request timestamp, business error code, and Request ID (if present in the response). Do not disclose your full API Key.

Error Code HTTP Status Code Possible Cause Recommended Action
key_invalid 401 API Key was not provided, or the API Key is incorrect or does not exist Check whether the API Key in the request header is complete and valid, and verify there are no redundant spaces or characters
key_disabled 401 The current API Key has been disabled Go to the console to check Key status; enable this Key or create a new API Key
user_disabled 403 The account to which the API Key belongs has been disabled Check account status; if further assistance is needed, please contact technical support
ip_rejected 403 The current request IP is not on the API Key's IP whitelist Add the outbound IP to the whitelist, or initiate requests from a network within the whitelist
rate_limited 429 The request frequency exceeds the rate limit of the current API Key or account Reduce concurrency or request frequency, and retry using an exponential backoff strategy; contact technical support if higher quotas are needed
key_quota_exhausted 429 The quota for the current API Key or account has been exhausted Go to the console to check quota and usage; retry after adjusting the quota
user_balance_exhausted 402 Insufficient available account balance Top up or adjust available balance before retrying
bad_request 400 Model name is missing from the request path or request body Fill in the correct model parameter according to the API documentation
bad_request 400 The request body is empty, malformed, or incompletely transmitted Check JSON format, Content-Type request header, and verify whether the request body is complete
bad_request 400 The model name in the request path does not match the model name in the request body Align the model name in the path and request body so that they are identical
bad_request 413 The request body exceeds the size allowed by the interface Reduce request content or file size; request bodies for standard non-binary endpoints should be less than 32 MiB
model_not_found 404 Incorrect model name, the current API Key lacks permission to use the model, or the model is temporarily unavailable Check model name and Key permissions, and verify the model is currently available; retry later or switch to another model if necessary
task_not_found 404 The asynchronous task ID does not exist, does not belong to the current account, or the task record has expired Check the task ID, and query using the account and API Key that created the task
unsupported_endpoint 404 The requested endpoint path or operation is currently not supported Check the request URL and operation name against the API documentation
client_cancelled 499 The client actively closed the connection or cancelled the request before the server completed its response Check client timeout settings and network connection; do not cancel requests prematurely when results are needed
internal_error 500 The platform is currently busy processing requests; temporarily rejecting requests to safeguard billing and data consistency Retry later; an exponential backoff strategy is recommended; contact technical support if the issue persists
internal_error 503 The platform is temporarily unable to retrieve authentication information for the API Key Retry later; contact technical support if the issue persists
internal_error 503 The platform is temporarily unable to verify account quota or balance Retry later, and check balance and quota status in the console
internal_error 503 Model service configuration is temporarily unavailable Retry later or switch to another available model; contact technical support if the issue persists
internal_error 503 The platform is temporarily unable to retrieve asynchronous task information Retry query later using the original task ID; do not create duplicate tasks immediately
upstream_rate_limited 429 The current model service is busy; all available channels have triggered rate limiting Reduce request frequency and retry later, or temporarily switch to another model
upstream_exhausted 502 Request failed to complete successfully after attempting multiple model service channels Retry later or switch to another model; contact technical support if the issue persists
stream_interrupted_after_first_byte 200 Streaming response has started returning, but the model service was interrupted during transmission, leaving the HTTP status code at 200 The client should also monitor error events within the stream; re-initiate the request as necessary for business logic

Error Response Example

The following example indicates that an invalid API Key was used in the request. The HTTP status code is 401, the business error code is key_invalid, and the error type is authentication_error:

{  "error": {    "code": "key_invalid",    "type": "authentication_error",    "message": "invalid api key"  }}

Client-Side Handling Recommendations

  • When receiving 400, 401, 402, 403, or 404, first check request parameters, credentials, balance, permissions, and resource existence, then retry after correction.
  • When receiving 429, please reduce request frequency and retry using an exponential backoff strategy.
  • When receiving 500, 502, or 503, retry after a brief wait; setting a maximum retry count is recommended to avoid infinite loops.
  • For streaming requests, continue listening for error signals in the response stream even if the HTTP status code is 200.
  • Do not disclose your full API Key in logs, tickets, or chat conversations.