DocsGet started
Claude Code & Codex
Route Claude Code, Codex, OpenCode, Copilot CLI and the agent SDKs through INFRO by changing the base URL and key, and see sessions and spend per person.
Coding agents speak their provider's own API, not Chat Completions. INFRO answers both: POST /v1/messages in Anthropic's Messages shape and POST /v1/responses in OpenAI's Responses shape. Point the agent at INFRO with an INFRO gateway key, and every request it makes goes through the same path as any other: your routes and failover, model allowlists, budgets and spend limits checked before the provider is called, guardrails, the request log with an estimated provider cost, and attribution. Your provider still bills you for the tokens; INFRO adds nothing to them.
Give each developer, or each agent, its own gateway key with a spend limit. A request that limit cannot cover is refused with 402 before the provider sees it, and the request log shows spend per key.
Claude Code
Set the base URL and an INFRO key. ANTHROPIC_AUTH_TOKEN is sent as Authorization: Bearer; ANTHROPIC_API_KEY as x-api-key. INFRO accepts either.
export ANTHROPIC_BASE_URL="https://api.infro.io"
export ANTHROPIC_AUTH_TOKEN="sk_infro_..."
# Keep MCP tools deferred behind INFRO (see "MCP tool search" below)
export ENABLE_TOOL_SEARCH=true
# Optional: attribute every request (newline-separated "Name: Value" pairs)
export ANTHROPIC_CUSTOM_HEADERS="X-INFRO-Workflow: claude-code"- Model names. Claude Code sends Anthropic's own ids (
claude-sonnet-5-5,claude-haiku-4-5-20251001); INFRO reads them as the catalog'santhropic/claude-sonnet-5.5. A route slug works too (ANTHROPIC_MODEL=your-route), but Claude Code does not recognize the name and assumes a 200K context window. - Lossless on Anthropic. On an Anthropic connection, or Claude on Vertex AI, the body Claude Code sends reaches the provider as written (thinking blocks and their signatures,
cache_controlbreakpoints, server tools, documents) and the answer comes back as the provider sent it. Theanthropic-betaheader is forwarded to Anthropic;anthropic-versionis accepted and pinned. - MCP tool search. Claude Code turns tool search off when
ANTHROPIC_BASE_URLis not Anthropic's, because most proxies do not forwardtool_referenceblocks, so every MCP tool definition is sent on every turn. INFRO forwards them on an Anthropic connection: setENABLE_TOOL_SEARCH=trueand MCP tools stay deferred. A model INFRO must translate to Chat Completions cannot run the search tool, so such a request is refused with400 unsupported_on_targetsbefore any call rather than sent with every tool loaded. - Streaming is relayed event by event. A provider that opens the stream and reports an error before any content (an
overloaded_error) is failed over to the next target, like one that refused outright. - Token counting.
POST /v1/messages/count_tokensasks the first Anthropic connection that serves the model; it is free and leaves no request row. With no such connection the answer is an estimate, andX-INFRO-Token-Count: estimatedsays so. - Model list. With
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1, Claude Code readsGET /v1/modelsand adds the Claude models your key can call to its/modelpicker. - Sessions. Claude Code's
x-claude-code-session-idheader becomes the request'ssession_idwhen you set none, so one session groups in the request log.
The Claude Agent SDK runs Claude Code, so it reads the same variables.
Codex
Add INFRO as a model provider in ~/.codex/config.toml. Codex sends the key from env_key as a bearer token, to <base_url>/responses.
model = "gpt-5.6-sol"
model_provider = "infro"
[model_providers.infro]
name = "INFRO"
base_url = "https://api.infro.io/v1"
env_key = "INFRO_API_KEY"
wire_api = "responses"
http_headers = { "X-INFRO-Workflow" = "codex" }Codex sends the whole conversation each turn (store: false, its reasoning carried back as encrypted content), which is what INFRO needs: see state below. On an OpenAI or Azure OpenAI connection the body goes to the provider as written, Codex's custom apply_patch tool and reasoning items included.
OpenCode
Point OpenCode's Anthropic provider at INFRO in opencode.jsonc, then run /connect, choose Anthropic, and paste your INFRO gateway key as the API key. OpenCode sends it as x-api-key, which INFRO accepts.
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"anthropic": {
"settings": { "baseURL": "https://api.infro.io/v1" },
"headers": { "X-INFRO-Workflow": "opencode" }
}
}
}GitHub Copilot CLI
Add INFRO as a provider in ~/.copilot/providers.json, then start Copilot with copilot --model infro/<model>. Copilot CLI needs a model with tool calling and streaming. It keeps the key in this file as plain text and does not read environment variables there, so give it a key of its own with a spend limit. It cannot send extra headers: label the key instead (see Attribute agent traffic).
{
"providers": [
{ "name": "infro", "type": "openai", "baseUrl": "https://api.infro.io/v1", "apiKey": "sk_infro_..." }
],
"models": [
{ "id": "anthropic/claude-sonnet-5.5", "provider": "infro" }
]
}OpenAI Agents SDK
from openai import AsyncOpenAI
from agents import set_default_openai_client
set_default_openai_client(
AsyncOpenAI(base_url="https://api.infro.io/v1", api_key="sk_infro_..."),
use_for_tracing=False, # the INFRO key is not an OpenAI key; trace with your own, or set_tracing_disabled(True)
)Attribute agent traffic
A coding agent cannot write INFRO's metadata into its request body, but it can send headers, and it already says who it is. INFRO reads both, so the request log groups an agent's sessions and the subagents they start, and Analytics shows estimated provider spend per person and per agent.
| Header | What it sets |
|---|---|
X-INFRO-Session-Id | The session. Up to 128 characters. |
X-INFRO-Parent-Session-Id | The session that started this one, for a subagent. |
X-INFRO-Agent | The agent's name when INFRO does not recognize it: 1-64 lowercase letters, digits and . _ -. |
X-INFRO-Tags | Tags as comma-separated name=value pairs: team=platform, repo=web. Up to 16; encode a literal comma as %2C. |
X-INFRO-Metadata | Other metadata keys, in the same name=value form. The reserved keys have their own headers and are refused here. |
- Agents INFRO recognizes. Claude Code (
x-claude-code-session-id, user agentclaude-cli/), Codex (originator: codex_cli_rs, user agentcodex_cli_rs/, itssession_idheader) and OpenCode (itsx-opencode-*headers, the session fromx-session-affinity, the parent fromx-parent-session-id). Their requests carry the agent's name and its own session id with nothing configured. Any other client is not guessed: it has no agent until it sendsX-INFRO-Agent. - W3C baggage. An OpenTelemetry setup that propagates
baggagecan carryinfro.session_id,infro.parent_session_id,infro.agent,infro.user_id,infro.workflow,infro.step,infro.feature,infro.trace_idandinfro.tag.<name>. A malformed baggage entry is dropped; a malformedX-INFRO-*header is refused with400 invalid_attributionnaming it. - Precedence. Body
metadatafirst, then theX-INFRO-*header, then baggage, thentraceparent(trace id only), then the agent's own header. Tags merge name by name in the same order. - Key labels. A gateway key can carry up to 16 labels (
team=platform,cost_center=4711), set on the Keys screen, or aslabelsonPOSTandPATCH /console/keysand in the management API. Every request the key makes carries them as tags, over a tag of the same name the request sends, so the code holding the key cannot change them. They filter astag.<name>and group once you promote the tag. - Per person and per agent.
GET /v1/usage?group_by=memberreports estimated provider spend per organization member (the creator of the key, or the member who ran a Playground or Studio request), andgroup_by=agentper agent; Analytics offers both as Person and Agent.GET /v1/requestsfilters bymember,agent,session_idandparent_session_id, and each request names itsagent,session_id,parent_session_idandmember_id.
Give each developer their own gateway key: their requests then group under their name with no header at all, and their spend limit is theirs.
To see what each person and each agent costs this budget cycle without opening Analytics, the Summary shows Cost per team member and Cost per coding agent cards once requests carry them: the average per person or agent, the largest ones with their change against the same days of the last cycle, all in estimated provider cost.
Which providers serve it, and how
| Endpoint | Sent as written (lossless) | Translated | Not served |
|---|---|---|---|
/v1/messages | Anthropic; Claude on Vertex AI; KIE's Claude models | Every other provider with chat: text, images and your own tools only | Providers without chat |
/v1/responses | OpenAI; Azure OpenAI; KIE's Codex models | Every other provider with chat: messages, images, function tools and JSON-schema output only | Providers without chat |
A translation drops what has no meaning for the other model (thinking settings and past thinking blocks, top_k, reasoning items, cache_control), names it in X-INFRO-Params-Dropped, and answers in the dialect you called. What it cannot carry without changing the request (a server tool such as web_search, a document block, a custom or hosted tool, MCP servers) makes that target ineligible for the request: it is left out of the chain, never sent a reduced request. When no target is left, the request is refused with 400 unsupported_on_targets naming what stood in the way. X-INFRO-Ingress says which way a request was served.
Anthropic does not support Claude Code on non-Claude models. INFRO can translate a Claude Code request to another model, but for failover give Claude Code's routes Claude targets on more than one provider (Anthropic, Claude on Vertex AI and Claude on Amazon Bedrock): those are served as written.
What is the same, and what differs
- Budgets and caps reserve the request's worst case before any provider is called, exactly as on chat completions. A refusal is
402in the dialect's envelope, and Claude Code shows its message. - Guardrails read every text block, tool input and tool result. Thinking blocks are not inspected: their signature covers the text, so a redaction would make Anthropic refuse the next turn. An output rule needs the whole answer: a streamed request it applies to is read whole from the provider, checked, then streamed to you, with SSE comments every few seconds meanwhile so the client does not time out.
- The answer keeps the provider's shape. INFRO's facts ride on response headers:
X-INFRO-Request-Id,X-INFRO-Model,X-INFRO-Provider,X-INFRO-Connection,X-INFRO-Route,X-INFRO-Ingress, and on an unstreamed answerX-INFRO-Cost-Estimate(USD, orunpriced). The request log has the rest. - The response cache does not serve these endpoints yet. Where it is on, the request log says
uncacheablewith the reasonendpoint. - Attribution. Send INFRO's
X-INFRO-Trace-Id,X-INFRO-Workflow,X-INFRO-Step,X-INFRO-FeatureandX-INFRO-User-Idheaders. On/v1/messages,metadata.user_idis Anthropic's field and is passed to Anthropic; INFRO's end customer isX-INFRO-User-Id. On/v1/responses, INFRO's reservedmetadatakeys are read and not forwarded.
State stays with the caller
INFRO keeps no responses. previous_response_id and conversation are refused with 400 unsupported_parameter on every target, because a failover to another account or another model could not resolve them; background: true is refused for the same reason. Send the whole conversation in input each turn. store is passed to a provider that takes the request as written: it is your own account.
Managed prompts
A managed prompt can be applied to these requests: the prompt field or X-INFRO-Prompt on /v1/messages, the X-INFRO-Prompt header on /v1/responses (the body's prompt there is OpenAI's own and passes through). The template becomes the request's system or instructions and its first turns, on every provider that serves the request.
Errors
Errors keep the documented taxonomy — type, code, message — inside each API's envelope: on /v1/messages, Anthropic's {"type": "error", "error": {…}}; on /v1/responses, the same {"error": {…}} as everywhere on /v1. A provider's refusal of the request carries the provider's own words in message, which is what Claude Code's automatic recovery reads. After a stream has started, a failure is the API's own stream event: error on /v1/messages, response.failed on /v1/responses.