Overview
AI Sonar’s Agent-First API enriches error responses with structured hints that AI agents can parse and act on immediately — no web searches, no doc lookups, no guesswork. OpenAI-compatible Chat Completions and Responses gateway errors may include optional fields such asdid_you_mean, suggestions, hint, retryable, and retry_after inside the error object. Anthropic Messages and Gemini endpoints keep their native error shapes and do not promise these extensions.
Error Hint Fields
For OpenAI-compatible gateway errors, all hint fields are optional extensions inside theerror object:
Error Code Examples
model_not_found (400)
When a model name doesn’t match any active model:did_you_mean resolution uses:
- Static alias mapping (from production error data)
- Normalized string matching (strips hyphens, case-insensitive)
- Edit distance matching (threshold ≤ 3)
did_you_mean, suggestions, and hint, then retry with a supported public model.
insufficient_balance (402)
When account balance is too low for the estimated cost:suggestions contains models cheaper than the estimated cost that the agent can switch to.
Temporary service errors (5xx)
When a model is temporarily unavailable, retry only when the response setsretryable to true:
retryable is false, follow hint or switch to a model listed in alternatives.
rate_limit_exceeded (429)
retry_after value is calculated from the actual rate limit window reset time.
OpenAI-compatible endpoints use the standard error envelope shown above. Anthropic-compatible and Gemini-compatible endpoints use their native response formats.
context_length_exceeded (400)
When input exceeds the model’s context window (with corrective hints):Native Endpoint Discovery
Do not infer native protocol availability from a model or provider name, or from Chat response headers. Before choosing a native endpoint, readGET /v1/models/{model} and use only a format in aisonar.accepted_request_formats. Native requests use only the advertised protocol; temporary service availability is still decided at request time.
An advertised request format controls endpoint availability; support for individual fields and tools remains service-specific.
/v1/models Enhancements
/v1/models now carries non-chat recommendation metadata that agents can use before they call image, video, music, 3D, TTS, STT, embedding, rerank, or translation endpoints.
When
recommended_for is present, agent_preferences is derived from a cached 24-hour success-rate snapshot:
- Window: 24 hours
- Snapshot cache: stale-while-revalidate
status = "ready"means the model has enough recent samples to participate in rankingstatus = "insufficient_samples"means the model stays visible but is not ranked ahead of scored models
Category Filtering
Recommendation Discovery
For non-chat workflows, agents should fetch the current recommended shortlist first:recommended_for values are:
imagevideomusic3dttssttembeddingreranktranslation
category and recommended_for are present, they must match exactly.
Recommended agent flow:
GET /v1/models?recommended_for=<scene>- Pick the first
agent_preferences.<scene>.status == "ready"model - Call the endpoint explicitly with
model=<selected> - On transient errors only, retry with the next
readymodel
llms.txt
A machine-readable API overview is available at:- First-call template with a working example
- Common model names (dynamically generated from usage data)
- All 12 API endpoints
- Filter parameters for model discovery
- Error handling guidance
llms.txt before their first API call can typically succeed on the first attempt.
Usage in Agent Code
Python (OpenAI SDK)
JavaScript (OpenAI SDK)
Design Principles
Fail fast, fail informatively
Errors return immediately with all the data an agent needs to self-correct.
No auto-routing
The API never silently substitutes a different model. The agent decides.
Data-driven suggestions
All recommendations come from production data, not hardcoded lists.
Backward compatible
All hint fields are optional. Existing clients see no difference.