Skip to content

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.

Shell or the env block of managed settings
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's anthropic/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_control breakpoints, server tools, documents) and the answer comes back as the provider sent it. The anthropic-beta header is forwarded to Anthropic; anthropic-version is accepted and pinned.
  • MCP tool search. Claude Code turns tool search off when ANTHROPIC_BASE_URL is not Anthropic's, because most proxies do not forward tool_reference blocks, so every MCP tool definition is sent on every turn. INFRO forwards them on an Anthropic connection: set ENABLE_TOOL_SEARCH=true and MCP tools stay deferred. A model INFRO must translate to Chat Completions cannot run the search tool, so such a request is refused with 400 unsupported_on_targets before 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_tokens asks 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, and X-INFRO-Token-Count: estimated says so.
  • Model list. With CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1, Claude Code reads GET /v1/models and adds the Claude models your key can call to its /model picker.
  • Sessions. Claude Code's x-claude-code-session-id header becomes the request's session_id when 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.

~/.codex/config.toml
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.

opencode.jsonc
{
  "$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).

~/.copilot/providers.json
{
  "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

Python
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.

HeaderWhat it sets
X-INFRO-Session-IdThe session. Up to 128 characters.
X-INFRO-Parent-Session-IdThe session that started this one, for a subagent.
X-INFRO-AgentThe agent's name when INFRO does not recognize it: 1-64 lowercase letters, digits and . _ -.
X-INFRO-TagsTags as comma-separated name=value pairs: team=platform, repo=web. Up to 16; encode a literal comma as %2C.
X-INFRO-MetadataOther 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 agent claude-cli/), Codex (originator: codex_cli_rs, user agent codex_cli_rs/, its session_id header) and OpenCode (its x-opencode-* headers, the session from x-session-affinity, the parent from x-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 sends X-INFRO-Agent.
  • W3C baggage. An OpenTelemetry setup that propagates baggage can carry infro.session_id, infro.parent_session_id, infro.agent, infro.user_id, infro.workflow, infro.step, infro.feature, infro.trace_id and infro.tag.<name>. A malformed baggage entry is dropped; a malformed X-INFRO-* header is refused with 400 invalid_attribution naming it.
  • Precedence. Body metadata first, then the X-INFRO-* header, then baggage, then traceparent (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 as labels on POST and PATCH /console/keys and 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 as tag.<name> and group once you promote the tag.
  • Per person and per agent. GET /v1/usage?group_by=member reports estimated provider spend per organization member (the creator of the key, or the member who ran a Playground or Studio request), and group_by=agent per agent; Analytics offers both as Person and Agent. GET /v1/requests filters by member, agent, session_id and parent_session_id, and each request names its agent, session_id, parent_session_id and member_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

EndpointSent as written (lossless)TranslatedNot served
/v1/messagesAnthropic; Claude on Vertex AI; KIE's Claude modelsEvery other provider with chat: text, images and your own tools onlyProviders without chat
/v1/responsesOpenAI; Azure OpenAI; KIE's Codex modelsEvery other provider with chat: messages, images, function tools and JSON-schema output onlyProviders 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 402 in 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 answer X-INFRO-Cost-Estimate (USD, or unpriced). The request log has the rest.
  • The response cache does not serve these endpoints yet. Where it is on, the request log says uncacheable with the reason endpoint.
  • Attribution. Send INFRO's X-INFRO-Trace-Id, X-INFRO-Workflow, X-INFRO-Step, X-INFRO-Feature and X-INFRO-User-Id headers. On /v1/messages, metadata.user_id is Anthropic's field and is passed to Anthropic; INFRO's end customer is X-INFRO-User-Id. On /v1/responses, INFRO's reserved metadata keys 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.

↑ ↓ navigate↵ open/ anywhere in docs