Smart Routing

Automatic provider routing, latency optimization, and graceful failover for LLM requests.

Smart Routing (model: "auto" or model: "auto-cn") evaluates healthy upstream models to dynamically select and route requests across OpenAI, Anthropic, and Gemini protocols.

Using model: "auto"

bash
curl "https://api.anyint.cloud/openai/v1/chat/completions" \
  -H "Authorization: Bearer $ANYINT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "auto",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Protocol Compatibility

  • OpenAI: POST /openai/v1/chat/completions and POST /v1/chat/completions
  • Anthropic: POST /anthropic/v1/messages and POST /v1/messages
  • Gemini: POST /gemini/v1beta/models/{model}:generateContent

Routing Evaluation, Fallback, and Billing

  • Candidate screening: Auto routing filters candidates by input modalities (text, image, audio, video, file), channel capabilities (such as json_schema/json_object and thinking-off), and context window limits. Non-text output, image generation tools, and stateful continuations (previous_response_id/conversation) require explicit models and return HTTP 400 auto_routing_request_unsupported.
  • Multi-attempt fallback: If a candidate attempt fails (including non-2xx responses, upstream refusals, timeouts, or transport errors), the gateway may try up to 3 distinct ranked models within a single evaluation. Each attempt repeats existing authorization, quota, rate-limit, routing, and funding checks under an independent execution ID; a denied check never authorizes upstream dispatch. Fallback stops immediately upon client cancellation or once the first response byte is delivered to the client; streams already started are never restarted.
  • Independent ledger evidence: Each attempt retains its own settlement evidence. Retrying does not convert uncertain upstream outcomes into zero cost.
  • Platform fee: A platform routing fee of min(20 * L / 1000000 + 0.01505, 0.2) credits—where L is the UTF-16 character length of the compressed Jev state—is billed strictly on the public parent request upon overall request success when scoring is used. Fees round half away from zero to micro-CNY (0.0001 credits / 4 decimal places). Failed final executions or cache hits incur no routing fee.
  • Session affinity & fallback scoring: When Redis session cache is healthy, consecutive turns with matching session identifiers (such as X-Claude-Code-Session-Id or X-OpenCode-Session-Id) bind to the same model, skipping scoring and fees on a valid hit. If that bound model fails, Auto bypasses the binding and scores once across remaining candidates; a successful scored fallback incurs the standard platform routing fee.