AI errors
Every error the AI binding can return, what it means, whether to retry, and how to fix it.
When the AI binding refuses a call, it says why in plain words and tells you what to do. Nothing is spent on a refused call. This page lists every error code, grouped by the kind of fix.
What an error looks like
An error is a JSON body with a stable code, a message you can show, and a how_to_fix sentence.
{ "type": "error", "error": { "type": "model_not_allowed", "code": "model_not_allowed", "message": "This tool is not set up to use \"claude-sonnet-5-5\".", "how_to_fix": "Allowed models: claude-haiku-5-5. Add the model to bindings.ai.models in the manifest and deploy again." } }
The same body works for both stock libraries. The OpenAI library reads error.message, error.type and error.code. The Anthropic library reads the top-level type and error.type. A few errors that happen before the AI part of the gateway, such as invalid_token, binding_not_declared and the gateway-wide rate_limited, have only code, message and how_to_fix. Always read code.
Every answer carries these headers:
x-request-idrequestId.x-ratelimit-limit and x-ratelimit-remainingRetry-Afterx-platform-modelCatching errors in your code
import { PlatformError } from '@cohostly/sdk' try { const reply = await platform.ai.messages({ model: 'gemini-3.5-flash-lite', messages }) return reply.text } catch (e) { if (!(e instanceof PlatformError)) throw e // e.status, e.code, e.message, e.howToFix, e.requestId if (e.code === 'ai_budget_exhausted') return 'The AI budget for this month is used up.' if (e.code === 'provider_key_needed') return 'This app needs an AI key. Ask the account owner.' return e.message }
import os from openai import OpenAI, APIStatusError client = OpenAI(base_url=os.environ["AI_BASE_URL"], api_key=os.environ["AI_API_KEY"], max_retries=0) try: reply = client.chat.completions.create( model="gemini-3.5-flash-lite", messages=[{"role": "user", "content": "Hello"}], ) except APIStatusError as e: print(e.status_code, e.code, e.message)
With the typed call, the network failing gives a PlatformError with status 0 and code network_error. Running outside the platform with no token gives code not_configured. Run locally with cohostly dev -- <command> (develop).
Good to know Stock libraries retry some errors on their own. A refusal such as
ai_budget_exhaustedwill not change by trying again, so consider turning their automatic retries off (max_retries=0ormaxRetries: 0) and deciding yourself. The typed call never retries.
Should I retry?
Never retryinvalid_request, request_too_large, model_not_allowed, model_unpriced, wrong_endpoint, provider_rejected_request, provider_key_needed, provider_key_invalid, provider_key_rejected, ai_budget_exhausted, invalid_token, binding_not_declared, method_not_allowed, not_found. The same request gets the same answer. Fix the cause.Retry after the waitrate_limited, too_many_concurrent_calls. Wait the Retry-After seconds.Retry laterai_paused, ai_unavailable, ai_platform_ceiling, provider_unavailable, internal. Wait, with growing pauses, and give up after a few tries.Setup mistakes
These come from the request or the settings file. Fix them in your code or cohostly.json, and deploy.
invalid_tokenX-Platform-Binding-Token. An app running on the platform gets the token as AI_API_KEY automatically. Check that you pass AI_API_KEY as the library's key.binding_not_declaredai binding. Add ai under bindings in cohostly.json and deploy.method_not_allowedAllow: POST.not_found/ai/v1/messages, /ai/v1/chat/completions and /ai/messages. Check that your base URL is AI_BASE_URL exactly.invalid_requestcontent-type: application/json, add a "model" and add a "messages" array with at least one message.request_too_largemodel_not_allowedbindings.ai.models. The message lists the models that are. Add the model and deploy again. Names must match exactly, so check spelling and case.model_unpricedcohostly ai-keys list. A name in your list that is not a real model can reach this error after it passes the allow-list.wrong_endpoint/ai/v1/messages. That address is for Anthropic's models only. Use /chat/completions for this model.provider_rejected_requestKeys
These apply to models paid with your own key. See bring your own key.
provider_key_neededcohostly ai-keys set <provider>.provider_key_invalidprovider_key_rejectedLimits and spending
rate_limitedRetry-After says when to try again. Slow down.too_many_concurrent_callsRetry-After is 2 seconds. Wait for one to finish.ai_budget_exhaustedRetry-After is the time until the 1st of next month, 00:00 UTC. For the project, raise bindings.ai.monthly_cap_usd (up to the account limit) and deploy, or wait. For the account, the message says to ask the account owner to raise the account limit, or wait for next month. Lower max_tokens if you are only just short.ai_platform_ceilingSee models and costs for how each cap is worked out.
Something is down for a moment
ai_pausedRetry-After is 60 seconds. Try again in a few minutes.ai_unavailableRetry-After is 5 seconds. Try again shortly.provider_unavailableRetry-After is 5 seconds on the first form. Try again in a moment.internalx-request-id if it keeps happening.ai_not_configured (HTTP 503, "AI is not set up on this platform yet") can only appear on a platform that has not connected a model provider. You should not see it on Cohostly.
When it fails after the answer starts
When you ask for a live reply (streaming), the gateway has already answered 200 before the model finishes. If something goes wrong after that, the connection ends. No JSON error is sent after the first words. Treat a stream that stops early as an incomplete answer. See HTTP and streaming.