Skip to content

LLM Gateway Options

Request options and wire formats of the LLM Gateway (OpenAI /v1). Payment is the same on every page: Paying with x402 or Paying with MPP.

Reasoning that fits the output cap

Reasoning tokens count against max_tokens (max_output_tokens on the Responses wire), so a reasoning model asked for more depth than a small cap can hold can spend the whole cap thinking and say nothing. On the chat completions, Messages and Responses wires the gateway does two things about that:

  1. Fit before the call. When your output cap is under the tier's default output budget (what a call that names no cap gets) and you ask a reasoning model for an effort above low, the request goes upstream at low, the effort the gateway itself picks for a small budget on the premium tier. A reasoning or thinking budget (reasoning.max_tokens, thinking.budget_tokens) above three quarters of the cap is lowered to leave a quarter of the cap for the answer, and not under the provider's minimum budget. A model whose reasoning does not count against the cap is sent your setting as is. Your cap is not raised, and the price or metered quote of the call is what it was. Streamed requests are fitted the same way.
  2. One retry. If a non-streamed answer still comes back empty because the cap ran out, the gateway runs the same model once more at its lowest supported effort (none where the model lists it on the chat completions and Responses wires; on the Messages wire the lowest effort the model lists, or thinking switched off for a thinking budget where the model runs without thinking), provided the call's price covers another run and the payment window leaves time for it. There is one such retry per call. After it the failover chain walks on as before, and a chain that ends empty is a 502 that is not settled on x402.

The answer says what changed:

"agent402_reasoning_adjusted": { "field": "reasoning.effort", "requested": "high", "used": "low", "reason": "max_tokens" }

field is the request field that was changed (reasoning.effort or reasoning.max_tokens on chat completions and Responses, effort or thinking.budget_tokens on Messages), requested is your value ("default" when you set none and the retry lowered the model's own default), used is what was sent (an effort name, a token budget, or "disabled" for thinking switched off), and reason is the cap field's name (max_tokens, max_output_tokens) for a fit before the call or empty_answer_retry for the retry. A streamed answer carries the same object as JSON in the X-Agent402-Reasoning-Adjusted response header. The field is absent when nothing was changed.

The auto tier - routing without picking a model

Send messages with no model field (or model: "auto") and the gateway routes the prompt to the top-ranked model for its task type. Routing is fully deterministic - lexical classification (code / reasoning / long-context / general) against a fixed, eval-derived ranking table; no LLM in the routing path, identical requests always route identically.

An optional quality field picks the ranking band at the same flat price (a per-request price cannot exist under x402's fixed per-route quote):

  • "fast" - cheapest/snappiest serving, right for loop turns
  • "balanced" - the default
  • "best" - the strongest models the price still covers

The response discloses the decision alongside the standard model field:

"agent402_router": { "category": "code", "quality": "balanced", "served": "deepseek/deepseek-v4.1-flash" }

Each ranking doubles as a failover chain: if a provider returns 502/503/504, the gateway walks down the list instead of charging you for an upstream error - every chain ends in the model the daily paid canary proves alive.

Response caching

Two policies over one cache (10-minute TTL, served before the paywall - a hit costs nothing):

  • Chat tiers - opt-in. LLM output is sampled, and a resend usually wants a fresh sample, so nothing is cached unless the request carries cache: true. A byte-identical opted-in repeat that carries your payment returns the stored response with X-Cache: hit, and the payment is not charged (a Tempo transfer sent before the call is final when sent, so it counts); without a payment the request gets the usual 402.
  • Embeddings - default-on. Embeddings are deterministic per model, so an identical repeat from the payer that paid for it is free automatically: it carries your payment as usual and the payment is not charged (a Tempo transfer sent before the call is final when sent, so it counts). Opt out with cache: false.

Keys are computed over the normalized body (model aliases and field order collapse; every sampling-relevant field is included), so equivalent requests share one entry, and each entry belongs to the payer that paid for it. An entry is stored, and a repeat served from it, only where that payer is proved before the paywall: an x402 v2 exact payment to this server whose EIP-3009 authorization is signed by the paying wallet's own key, inside its validity window, with a fresh authorization each time (one already used reads nothing); a Tempo payment from the same verified sender; or the same credits key. A request from another payer, or paid any other way (x402 v1, Permit2 or upto, a smart-contract wallet's signature, a non-EVM network, a card), is a fresh call and is charged as usual, repeats included.

Image inputs

A chat or Responses request may carry images (image_url parts, or input_image on the Responses wire). On the GPT-5.6 and GPT-6 model families an image part that names no detail is sent at high; name auto to have the image read at its own size, or low for the smallest read. The quote counts each image from the level sent and, when the picture is inline, from its real width and height.

Prompt caching

Every chat call asks the upstream to cache the prompt prefix (a top-level cache_control: {type:"ephemeral"}, 5-minute TTL) and pins your turns to one provider (session_id), so a multi-turn agent conversation is served from the provider cache on repeated prefixes. Same flat price to you either way. Send cache_control: false to opt out. The budget tiers (nano, auto) additionally pick the cheapest provider under their price cap; pro and premium keep the upstream's default provider balancing.

Rerank

POST /v1/rerank ($0.002) speaks the Cohere rerank wire: {query, documents[], top_n} in, results[{index, relevance_score, document}] out, served by cohere/rerank-v3.5. Up to 50 documents (1,600 chars each, 40k total) and a 500-char query per call. Deterministic, so a byte-identical repeat within 10 minutes is served free from cache to the payer that paid for it, under the rules in Response caching (cache:false opts out). Pair it with /v1/embeddings: embed, recall your top candidates, rerank them.

Anthropic Messages wire format

The same five tiers also speak the Anthropic Messages wire: POST /v1/nano/messages, /v1/auto/messages, /v1/messages, /v1/pro/messages, /v1/premium/messages (same prices, models, caps and failover as each tier's chat route). Point the Anthropic SDK, Claude Code or the Agent SDK at https://agent402.tools/v1 (or /v1/pro, /v1/premium) with an x402-paying fetch and call messages.create as usual: system, content blocks (text, image, tool_use, tool_result), client tools, thinking, stop_sequences, streaming (message_start … message_stop). Any model on the tier is served through this wire (Claude natively, others translated upstream). max_tokens is required by the wire and clamped to the tier cap; a reply that spends its whole cap thinking and says nothing is not served (the same model gets one retry at its lowest depth, then the failover chain walks on, and an exhausted chain is a 502, not settled on x402; see Reasoning that fits the output cap). On Claude 4.7+ (Opus 5, Sonnet 5, Fable 5.1) the depth control is top-level effort (low, medium, high, xhigh, max), validated against the model's own list from /v1/models and refused with that list; older Claude takes thinking.budget_tokens instead. speed other than standard is refused: the priority endpoint bills twice the model's list price and sits outside every tier's price.

OpenAI Responses wire format

The same five tiers also speak the OpenAI Responses wire: POST /v1/nano/responses, /v1/auto/responses, /v1/responses, /v1/pro/responses, /v1/premium/responses. Point responses.create() (or the OpenAI Agents SDK) at https://agent402.tools/v1 (or a tier prefix) through an x402-paying fetch. input as a string or item list, instructions, function tools, text.format, reasoning, streaming (response.created … response.completed) all work; server-side tools (web search, file search, computer use, MCP) are not served, and there is no stored conversation state (store is always false, previous_response_id is refused) - send the full input each call.

POST /v1/grounded/chat/completions ($0.03) is the auto router plus a live web search on every call (up to 5 results): the model answers from the results and the reply carries url_citation annotations. Omit model (or send auto) and the gateway picks the model by task type; the response adds agent402_router. :online model variants are refused on the other tiers (pro and premium accept the bounded agent402:web_search server tool instead), and here search is part of the flat price. Never cached.

Other hosts (Claude Code, Cursor, Continue, ElizaOS, AgentCore, any OpenAI SDK): https://agent402.tools/guides/agent-hosts