MarsAI developer guide
Troubleshoot MarsAI API errors
Use the status and error body to decide whether a request needs a configuration change, more credits or a bounded retry.
Reviewed . Checked against the current MarsAI /v1 behavior and published catalog.
Start with the response
Record the status, request time, endpoint and safe error fields. Never log the Authorization header, raw API key, full prompt or private response content. Read the JSON error body because the status alone may cover more than one cause.
| Status | Meaning | What to check |
|---|---|---|
| 400 / 409 / 422 | The request shape or state was rejected. | Validate JSON, endpoint fields, tool history, model ID and any continuation reference. |
| 401 | The key is missing or not accepted. | Check the bearer header and whether the key remains active. Never send a key in the URL. |
| 402 | The account cannot cover a paid request. | Review eligible Free and Premium Credit balances plus the selected model's billing method. |
| 403 | The account or model is not permitted. | Check account verification, model restrictions and the error message. |
| 413 | The HTTP request body is too large. | Reduce embedded data or conversation size. The gateway caps raw JSON bodies at 16 MiB. |
| 429 | A request limit or temporary capacity limit was reached. | Read the message and Retry-After header when present. Wait before a bounded retry. |
| 5xx | The request could not complete because of a gateway, server or model route failure. | Keep the time, public model ID and safe error details. Check whether any streamed output arrived before retrying. |
A bounded retry pattern
Retry a temporary 429 or 5xx only. Set a maximum attempt count, add random jitter to increasing waits and stop when the budget ends. Do not resend an unchanged 400, 401, 402 or 403.
async function sendWithRetry(sendRequest) {\n for (let attempt = 0; attempt < 3; attempt++) {\n const response = await sendRequest();\n if (response.ok) return response;\n if (![429, 500, 502, 503, 504].includes(response.status)) {\n throw new Error("Request needs attention: " + response.status);\n }\n if (attempt === 2) break;\n const wait = Math.min(1000 * (2 ** attempt), 8000) + Math.random() * 250;\n await new Promise((resolve) => setTimeout(resolve, wait));\n }\n throw new Error("Temporary service error; retry budget exhausted");\n}
This pattern does not make a repeated side effect idempotent. Honor a valid Retry-After value when the response supplies one.