Skills for AI/ML API, one API for 10,000+ AI models and tools: choosing models, chat on any protocol, images, video and audio jobs, speech, decision models, webhooks, batches, errors, costs and sandbox testing
93%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Medium
Suggest reviewing before use
api.aimlapi.com fails and you need to know why and what to doMost errors are application/problem+json with title, status, message, requestId and an error object; validation errors list each bad field in error.details[] (path, reason). Provider errors may use the OpenAI shape {"error": {"message", "type", "code"}}. A code, when there is one, is in top-level code or error.code. Examples and a defensive parser: references/error-shapes.md.
Every response has an x-request-id header (and requestId in error bodies). Log it; support needs it.
It says whether to fix the request, wait, or retry.
Retry 429 and 500, 502, 503 with Retry-After or exponential backoff with jitter, three or four times at most: helpers in Python and TypeScript are in references/retry.md.
A 200 can still be an error: after 60 seconds the API keeps the connection open with spaces, which fixes the status at 200, so a later failure arrives as {"error": {...}} in the body, without cost headers. Check the body too (the helpers do).
The OpenAI and Anthropic SDKs already retry 429 and 5xx (max_retries, default 2): raise max_retries instead of wrapping them in a second loop, and set timeout high, since a long generation can take minutes.
A timeout on your side does not cancel the request on ours: it may finish and be charged.
aimlapi-async-jobs, aimlapi-speech); never hold a request open for a generation. A 504 or timeout on a poll is safe to retry; resubmitting is not.504. A row in GET /v2/logs appears only once the request has ended, so a missing row means "still running or never arrived", not "safe to retry". Send X-Client-Request-Id, wait, then list rows with explicit start and end (a period window is cached for 60 seconds) and match client_request_id. Retry only when its row says failed, or when none has appeared long after any answer could have come (row shape: aimlapi-costs). Work that can outlast your timeout belongs on an async endpoint.Idempotency-Key on create (aimlapi-batch).A content_policy_violation is the provider refusing the content. Refusals count toward restrictions on the end user, the provider's models, or the account, so:
safety_identifier (a stable, anonymous hash of your end user's id) on every request, so a restriction lands on that one user instead of the whole account.403 "Usage policy restriction" names what is restricted and until when. Retrying before then does not help.Details: https://docs.aimlapi.com/capabilities/safety-guidance.md
400, 401, 403, 404; they will fail the same way and some count against you.Retry-After.x-request-id of the last attempt.message verbatim when you cannot fix the cause.[ -n "$AIMLAPI_API_KEY" ]), never print it.| Response | Retry? | Do |
|---|---|---|
400 "Validation failed", error.details[] | no | fix each path from the model's docsJson (aimlapi-models) |
400 "… does not support 'system' with this model" | no | move the system text into the user message |
400 content_policy_violation, 403 "Usage policy restriction" | no, not on another model either | § Content policy |
401 "requires a valid API key" | no | the key is missing, revoked or mistyped in the calling process |
403 "You've run out of credits" / model_not_allowed | no | top up at https://aimlapi.com/app/billing / allow the model on the key |
403 Cloudflare page, error_code: 1010 | no | send your own User-Agent; if it persists, contact support with the ray_id |
404 | no | wrong path or base URL, or a withdrawn model (GET /v1/models/deprecations) |
429 | yes | wait Retry-After, else exponential backoff with jitter |
500, 502, 503 | yes, a few times | backoff; a lasting "model is under maintenance" goes to support with the request id |
504 "Generation timeout" | carefully | § Do not pay twice |
[sandbox:error=429], …=503, …=403; aimlapi-sandbox).400 is not retried; a 429 waits for Retry-After.