
When a request to the agent fails, the API answers with an HTTP status and an error object, with code, message, correlation_id and details. The two errors caused by the agent are agent_paused and model_not_found. The others are the ones from the rest of the AI API.
409 agent_paused
The agent is paused. Turn it back on in the Agents tab of All in One AI, with Activate. The id does not change, so the program works again without changes. More in pausing, activating or deleting an agent.
404 model_not_found
The API did not find what is in model. With agents, these are the causes:
|
|
|
Check with GET /v1/models?type=agent: if the agent is not in that key's list, the request will not find it either. See listing your agents through the API.
The other errors
| Status | Code | What to do |
| 401 | unauthorized | The key is missing, wrong, revoked or expired. Check it or create another. |
| 402 | insufficient_credits | The credits do not cover the reservation. details.required says how much is needed and details.balance how much you have. Buy credits or lower max_tokens. |
| 403 | insufficient_scope | The key does not have ai:write. Create one with the right permission. |
| 422 | validation_failed | A field is missing or a value is not valid. See details. |
| 429 | rate_limited | You went over the requests per minute limit. Wait the seconds in Retry-After. |
| 502 | upstream_error | The AI service did not respond as expected. Try again shortly. |
In your code
The OpenAI SDKs read the message from error.message and raise an exception with the HTTP status. In Python it is APIStatusError:
import os
from openai import OpenAI, APIStatusError
client = OpenAI(base_url="https://api.mozout.co.mz/v1", api_key=os.environ["MOZOUT_API_KEY"])
try:
completion = client.chat.completions.create(
model="agent/7c1e9a42-b35d8f06-a2c4e719-5d0b3f8e",
messages=[{"role": "user", "content": "Hello!"}],
max_tokens=400,
)
print(completion.choices[0].message.content)
except APIStatusError as e:
print(e.status_code, e.message)
print("Correlation ID:", e.response.headers.get("X-Correlation-ID"))
Keep the Correlation ID in your program's logs. If you contact us about a request, that is how we find it.
|
Want an agent that works without surprises in your program? See All in One AI. See All in One AI |
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from 396,00 MT/mo (3-year plan, with coupon) See plans |











