provider-claude-code
v0.3.1Claude Code (Pro/Max subscription) Messages API provider worker; implements provider::claude-code::stream and provider::claude-code::refresh_models behind llm-router, using the OAuth token of each turn's Claude Code account from the tmux worker when it holds the accounts, else from the auth-credentials vault or ~/.claude/.credentials.json.
Install
iii call compose::add worker=provider-claude-codeRun in your project with the iii engine running. Exact versions are immutable and digest-pinned.
Full markdown
/registry/workers/provider-claude-code.md. Paste it into an LLM prompt or pipe it through curl from a worker.Install
iii call compose::add worker=provider-claude-code@0.3.1Dependencies
Readme
provider-claude-code
Claude Pro/Max subscription provider worker behind
llm-router. It lets the
stack generate against a personal Claude Code subscription (billed to the plan)
instead of a pay-per-token API key, by reusing the OAuth credentials the Claude
Code CLI already stores locally and speaking Anthropic's Messages API with a
Bearer token. It is the Claude analog of
provider-openai-codex.
Implements the provider protocol from tech-specs/2026-06-agentic/llm-router.md:
provider::claude-code::stream (Messages SSE → AssistantMessageEvent frames
into a router-owned channel), provider::claude-code::refresh_models (fetches
and reconciles the model catalog, with a curated fallback), and
provider::claude-code::count_tokens (exact prompt token counts behind
router::count_tokens). For API-key
billing (teams/CI/production), use provider-anthropic
instead — that provider speaks the same API with ANTHROPIC_API_KEY.
⚠️ Terms-of-service caveat — local/personal dev only. This drives a personal Claude Pro/Max subscription outside the official Claude Code CLI: it sends the Claude Code identity system prompt and the
anthropic-beta: oauth-2025-04-20header soapi.anthropic.comaccepts the subscription OAuth token. That is plausibly against Anthropic's terms and may risk account action. Use it for local, personal development. For team/CI/production, use official API-key billing (provider-anthropic). You assume the risk.
Credentials
This worker is a dumb token consumer — login and refresh live out-of-band.
Every call gets its token through one account source (src/accounts.rs), which
decides between two paths:
Accounts held by the tmux worker
When the tmux worker registers tmux::accounts::credential, it
holds the Claude Code accounts, and every token comes from it:
- Which account: a stream uses
provider_options.account, the concrete account id the harness froze on the turn. Without it (an older harness, a directrouter::chat), and for model discovery and token counting, which have no turn, the provider uses the global account: it reads the id fromtmux::accounts::list'sglobalfield (kept 30 s, and named again after a 401 or anunknown_account) and asks for that id, so the token cache never serves the previous account after a switch. Aglobalofnull(no account signed in as the global one) isauth_expired. tmux's answer must name the account asked for when it names one; a token for another account is never used. - A pinned account never falls back: a stream with
provider_options.accountruns on that account's token or not at all. Without the tmux worker, or while it cannot be told whether tmux holds the accounts, it fails astransientinstead of running on the~/.claudetoken, which is another account (and its quota). - Detection: "tmux manages the accounts" means
engine::functions::list {prefix: "tmux::accounts::", include_internal: true}liststmux::accounts::credential. The answer is kept 30 s. A list call that fails is not absence: it is tried three times (250 ms, then 500 ms apart); then the last answer stands, and with none known the call fails astransient(it never takes the vault path, and the boot import below runs only on a confirmed absence). Afunction_not_foundfrom tmux drops the answer so the next call looks again. The function is the signal rather than tmux's account registry (claude.managedin its usage): tmux serves and renews the global account's token even without a registry, so a vault copy of that token would drift from the one tmux renews. - No vault: while tmux manages the accounts, the provider neither reads nor
writes the
auth-credentialsvault, and the boot import below is skipped. - Cache: each account's token is cached by id until 60 s before its
expires_at_ms; one without an expiry is never cached, and an expired one is never sent. An answer that arrives after the account's token was dropped (a 401 elsewhere) is used once and not cached. tmux renews a token that expires within five minutes. - A 401: the provider drops that account's token, asks tmux once more and,
when it gets a different token, sends the request again once. A 401 that
survives is
auth_expired("Claude Code rejected the sign-in of the account …"). When tmux gives no token on that second ask, its own refusal stands (below):busystaystransient, not a sign-in to redo. Streaming, discovery and token counting all do this. - tmux's refusals become the turn's error frame:
not_signed_inandtoken_expired→auth_expired,busy(a renewal under way) or tmux not answering →transient(the router retries),unknown_account→permanent. Discovery keeps the last slice on all of them, and fails withauth_expiredwhen the global account must sign in again.
Without the tmux worker
Today's path, unchanged, for every call on the global account (a stream
without provider_options.account, model discovery, token counting):
- Vault (intended authority): the
auth-credentialsworker (auth::get_token), populated by anoauth-claude-codesign-in flow. A near-expiry token makes this provider call the vault-owned refresh (oauth::claude-code::refresh); it never calls the OAuth token endpoint itself. That worker/flow is out of scope here — this provider only consumes and calls. The credential record it expects is{ type: "oauth", access_token, refresh_token?, expires_at?(seconds), provider_extra: { subscription_type?, scopes? }, refresh_fn: "oauth::claude-code::refresh" }. - Local dev fallback: when no vault is running, the worker reads the
claudeCLI's own credential (read-only — the CLI owns its refresh, including rotating the refresh token):${CLAUDE_CONFIG_DIR:-$HOME/.claude}/.credentials.jsonand, on macOS, the "Claude Code-credentials" login Keychain item (viasecurity find-generic-password), taking whichever expires later — the macOS CLI stops updating the file once it uses the Keychain. TheclaudeAiOauth.expiresAtis epoch milliseconds; it is stored as seconds in the vault shape. Requires host access to those stores, so it does not apply to sandboxed/microVM-managed workers. On boot the worker also does a one-time, read-only import of that credential into the vault when the vault is present but empty (never written back).
API-key credentials are rejected — they belong on provider-anthropic under
provider id anthropic.
Behavior
- Registration: self-declares via
router::provider::registerwith backoff, and re-declares on everyrouter::on-readyevent (it observes that function at boot). It advertises dynamic model listing andcredential_env_var: None(OAuth-only); identity binds via theregistration_tokenpersisted in state (scopeprovider-claude-code). - Models: attempts the authenticated
GET /v1/modelsat startup, on explicit refresh, after router readiness, and every ~15 minutes. Picker-visible results become namespaced router ids (claude-code/<upstream-id>). If the models endpoint refuses the subscription OAuth token (403) — or returns nothing — a small curated fallback slice is reconciled instead of blanking the catalog, so streaming still works. A 401 (the token itself was rejected) or an expired token fails the refresh withauth_expired, so setup asks for a new sign-in instead of listing models a chat cannot use. Those failures and transient ones preserve the router's last-known-good slice. Namespacing preventsAmbiguousModelcollisions withprovider-anthropic. - Request: Messages API —
messages,tools,max_tokens,stream: true, optional adaptivethinking+output_config.effort, and automatic prompt caching.systemis always an array whose first block is the Claude Code identity line (a wire-only artifact required by the subscription backend); an optional router-supplied harness prompt follows as a second block. Headers:authorization: Bearer,anthropic-version: 2023-06-01,anthropic-beta: oauth-2025-04-20. - Token counting:
provider::claude-code::count_tokens(behindrouter::count_tokens) posts the stream body (identity block, thethinking/output_config.effortmapped from an optionalthinking_level, the trailing-assistant drop; nomax_tokens,streamor cache markers) to the messages endpoint'scount_tokenssibling (/v1/messages/count_tokens) with the same OAuth credential and headers as streaming, for an exact provider-metered count (estimator: "provider"). It never runs the model and costs nothing; a non-2xx answer is returned as an error so the router can fall back to an estimate. - SSE:
content_block_delta(text_delta→ text,thinking_delta→ thinking,input_json_delta→ tool calls),message_delta→ usage,message_stop→ terminal. Unknown event types are ignored (forward-compat). - Liveness / errors:
pingat least every 30s of silence; 401/403 →auth_expired, 429 →rate_limited, context-overflow →context_overflow, 5xx/network →transient, other 4xx →permanent. The router owns retry policy. - Usage limit: a 429 whose
anthropic-ratelimit-unified-statusisrejectedmeans the account's subscription limit is reached, not a busy moment (limits::is_usage_limit). Its error frame staysrate_limitedand carrieserror_details: {usage_limit: true, window?, resets_at_ms?}: the window fromanthropic-ratelimit-unified-representative-claim(five_hour→five_hour,seven_day*→week, anything else left out) and the reset fromanthropic-ratelimit-unified-reset(else the window's own-5h-reset/-7d-reset), unix seconds turned into milliseconds. The router never retries it and hands the details to the caller. These are the headers the Claude Code CLI reads; Anthropic's public API docs do not list theunifiedfamily.
Running
Standard worker CLI: --url (engine WebSocket, default ws://127.0.0.1:49134,
or III_URL), --manifest (print the registry manifest and exit), --config
(accepted but ignored — this worker has no file-based config).
# ensure `claude` has signed in (dev): ~/.claude/.credentials.json or, on macOS, the Keychain
cargo run -- --url ws://127.0.0.1:49134The prompt-cache anchors can be disabled with PROVIDER_CLAUDE_CODE_CACHE=0.
When the router forwards system_sections, the identity block is followed by
one text block per section and the marker lands on the block flagged
cache_boundary (the frozen agent-profile prefix) instead of the last block,
whatever its size (Anthropic applies its per-model token minimum over the
whole prefix and silently skips a short one), so the per-session tail no
longer invalidates the shared entry. That boundary
block and the tools marker use the 1-hour cache (ttl: "1h"); the messages
anchor stays at 5 minutes unless PROVIDER_CLAUDE_CODE_CACHE_MESSAGES_TTL=1h
asks for one hour there too (only on top of the 1-hour prefix), for agents that
sleep between turns, such as an orchestrator waiting on its children: one that
wakes after more than five minutes otherwise writes its whole conversation
again. PROVIDER_CLAUDE_CODE_CACHE_TTL=5m restores the 5-minute cache
everywhere.
Tests
cargo test # unit modules, model-discovery/upstream TCP stubs, schema goldensRegenerate the wire-schema goldens with UPDATE_GOLDENS=1 cargo test.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
not configured: sign in with Claude Code … |
no vault credential and no local claude credential (~/.claude/.credentials.json, or the Keychain on macOS) |
run the oauth-claude-code sign-in, or claude (login) |
| local fallback is used on each request | auth-credentials vault not running |
start the vault for shared/refreshing credentials, or keep relying on the local claude credential fallback |
requires a Claude Pro/Max OAuth login … API keys belong on provider-anthropic |
credential is an API key | this provider is OAuth-only; use provider-anthropic for keys |
Your Claude Code sign-in has expired … |
the local claude token expired and no refresh worker is registered |
run claude once to refresh it, or register the oauth-claude-code refresh flow |
The Claude Code account "…" is not signed in … / … has expired and could not be renewed … |
the tmux worker holds the accounts and that one has no usable sign-in | sign in to that account again through the tmux worker |
The Claude Code account "…" is busy renewing its sign-in … |
tmux was renewing that account's token | nothing: the router retries; send again if it gave up |
This Claude Code account has reached its usage limit. |
the account's five-hour or weekly subscription limit (error_details.usage_limit) |
wait for resets_at_ms, or switch the turn to another account |
The Claude Code accounts could not be read (the tmux worker that holds the account "…" is not running) … |
a turn pinned to an account, with the tmux worker stopped (or its function list unreadable) | start the tmux worker; the router retries meanwhile |
| the vault is never consulted | the tmux worker registers tmux::accounts::credential, so it holds the accounts |
expected while the tmux worker runs; without it the provider is back on the vault / ~/.claude path within 30 s |
Claude Code rejected the current sign-in … |
Anthropic answered 401: the token was revoked, replaced, or is corrupted | run claude and /login again |
Anthropic refused this request for the current Claude Code sign-in … |
Anthropic answered 403: the token is valid but not allowed this request | signing in again does not help; check the reason in parentheses, such as the plan's access to the model |
| catalog shows only the curated fallback models | GET /v1/models refused the OAuth bearer (403), or returned nothing |
expected — streaming still works, and the live list returns once the endpoint accepts the token |
| upstream 401 despite a valid token | the request no longer resembles Claude Code | keep the identity system block first and the anthropic-beta: oauth-2025-04-20 header; a future backend change may require a user-agent compat header |
| model routes ambiguously | a claude-code/* id collided with another provider |
keep ids namespaced; or pin provider: "claude-code" |
API reference (JSON)
{
"functions": [
{
"description": "Cancel the in-flight upstream stream for a request_id (router::abort fan-out), stopping billed generation immediately.",
"metadata": {
"internal": true
},
"name": "provider::claude-code::abort",
"request_schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Input of a provider's `provider::<id>::abort`: actively cancel the in-flight upstream stream for `request_id` (the router's `request_id`, delivered to the provider as `resolution_key`) so billed generation stops immediately instead of waiting for the provider to notice the closed channel on its next write.",
"properties": {
"request_id": {
"type": "string"
}
},
"required": [
"request_id"
],
"title": "ProviderAbortRequest",
"type": "object"
},
"response_schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Output of `provider::<id>::abort`. `aborted: false` means the request was unknown — already finished, never started, or aborted before (idempotent).",
"properties": {
"aborted": {
"type": "boolean"
}
},
"required": [
"aborted"
],
"title": "ProviderAbortResponse",
"type": "object"
}
},
{
"description": "Count prompt tokens for {model, system_prompt?, tools?, thinking_level?, messages} via the upstream count_tokens metering endpoint with the Claude Code subscription OAuth token; never runs the model and costs nothing.",
"metadata": {
"internal": true
},
"name": "provider::claude-code::count_tokens",
"request_schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"AgentFunction": {
"description": "Function invocation schema — what a provider sees as a `tools` array entry (README § Function invocation schema; adapter boundary). These describe iii functions exposed to the model, not provider-native tools.",
"properties": {
"description": {
"type": "string"
},
"execution_mode": {
"type": [
"string",
"null"
]
},
"label": {
"type": [
"string",
"null"
]
},
"name": {
"type": "string"
},
"parameters": true
},
"required": [
"description",
"name",
"parameters"
],
"type": "object"
},
"AgentMessage": {
"anyOf": [
{
"$ref": "#/definitions/AssistantMessage"
},
{
"$ref": "#/definitions/FunctionResultMessage"
},
{
"$ref": "#/definitions/CustomMessage"
},
{
"$ref": "#/definitions/UserMessage"
}
],
"description": "The canonical transcript message union. Untagged: the single-variant role tags disambiguate deserialization."
},
"AssistantMessage": {
"properties": {
"content": {
"items": {
"$ref": "#/definitions/ContentBlock"
},
"type": "array"
},
"error_details": {
"anyOf": [
{
"$ref": "#/definitions/ErrorDetails"
},
{
"type": "null"
}
],
"description": "What `error_kind` alone does not say, such as an account's usage limit. Omitted when absent; readers that don't know it ignore it."
},
"error_kind": {
"anyOf": [
{
"$ref": "#/definitions/ErrorKind"
},
{
"type": "null"
}
]
},
"error_message": {
"type": [
"string",
"null"
]
},
"model": {
"type": "string"
},
"native_stop_reason": {
"type": [
"string",
"null"
]
},
"provider": {
"type": "string"
},
"role": {
"$ref": "#/definitions/AssistantRoleTag"
},
"stop_reason": {
"$ref": "#/definitions/StopReason"
},
"timestamp": {
"format": "int64",
"type": "integer"
},
"usage": {
"anyOf": [
{
"$ref": "#/definitions/Usage"
},
{
"type": "null"
}
]
},
"warnings": {
"items": {
"type": "string"
},
"type": [
"array",
"null"
]
}
},
"required": [
"content",
"model",
"provider",
"role",
"stop_reason",
"timestamp"
],
"type": "object"
},
"AssistantRoleTag": {
"enum": [
"assistant"
],
"type": "string"
},
"ContentBlock": {
"description": "Content blocks — the atomic units of message content (README § Content blocks).",
"oneOf": [
{
"properties": {
"text": {
"type": "string"
},
"type": {
"enum": [
"text"
],
"type": "string"
}
},
"required": [
"text",
"type"
],
"type": "object"
},
{
"properties": {
"attachment_id": {
"description": "Optional link to the stored original in the session-manager attachment store. Transcript bookkeeping for lazy readers only: the harness clears it before `router::chat`, and no provider mapping reads it. Tolerated here so a block that still carries it deserializes instead of failing the request; omitted on the wire when absent.",
"type": [
"string",
"null"
]
},
"data": {
"type": "string"
},
"mime": {
"type": "string"
},
"type": {
"enum": [
"image"
],
"type": "string"
}
},
"required": [
"data",
"mime",
"type"
],
"type": "object"
},
{
"description": "Reference to an original upload in the session-manager attachment store. A REFERENCE ONLY (never inline bytes); the harness strips it before `router::chat`. Tolerated here so a stray block deserializes instead of failing the request; every counter/mapping emits nothing for it.",
"properties": {
"attachment_id": {
"type": "string"
},
"mime": {
"type": "string"
},
"name": {
"type": "string"
},
"size": {
"format": "uint64",
"minimum": 0,
"type": "integer"
},
"type": {
"enum": [
"file"
],
"type": "string"
}
},
"required": [
"attachment_id",
"mime",
"name",
"size",
"type"
],
"type": "object"
},
{
"properties": {
"signature": {
"type": [
"string",
"null"
]
},
"text": {
"type": "string"
},
"type": {
"enum": [
"thinking"
],
"type": "string"
}
},
"required": [
"text",
"type"
],
"type": "object"
},
{
"description": "Opaque redacted thinking payload — replayed verbatim on the Anthropic wire.",
"properties": {
"data": {
"type": "string"
},
"type": {
"enum": [
"redacted_thinking"
],
"type": "string"
}
},
"required": [
"data",
"type"
],
"type": "object"
},
{
"properties": {
"arguments": true,
"function_id": {
"type": "string"
},
"id": {
"type": "string"
},
"type": {
"enum": [
"function_call"
],
"type": "string"
}
},
"required": [
"arguments",
"function_id",
"id",
"type"
],
"type": "object"
},
{
"properties": {
"content": {
"items": {
"$ref": "#/definitions/ContentBlock"
},
"type": "array"
},
"function_call_id": {
"type": "string"
},
"is_error": {
"type": [
"boolean",
"null"
]
},
"type": {
"enum": [
"function_result"
],
"type": "string"
}
},
"required": [
"content",
"function_call_id",
"type"
],
"type": "object"
}
]
},
"CustomMessage": {
"properties": {
"content": {
"items": {
"$ref": "#/definitions/ContentBlock"
},
"type": "array"
},
"custom_type": {
"type": "string"
},
"details": true,
"display": {
"type": [
"string",
"null"
]
},
"role": {
"$ref": "#/definitions/CustomRoleTag"
},
"timestamp": {
"format": "int64",
"type": "integer"
}
},
"required": [
"content",
"custom_type",
"role",
"timestamp"
],
"type": "object"
},
"CustomRoleTag": {
"enum": [
"custom"
],
"type": "string"
},
"ErrorDetails": {
"description": "What an error's kind alone does not say. Optional on the assistant message and on the router's `ErrorShape`, and serialized only when present, so every reader that does not know it ignores it: `ErrorKind` itself keeps its five values, because its copies elsewhere deserialize it strictly.",
"properties": {
"resets_at_ms": {
"description": "When that limit resets, in milliseconds since the epoch.",
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"usage_limit": {
"default": false,
"description": "The account's usage limit is reached: a `rate_limited` that waiting a moment does not fix, so the router never retries it.",
"type": "boolean"
},
"window": {
"anyOf": [
{
"$ref": "#/definitions/UsageWindow"
},
{
"type": "null"
}
],
"description": "Which limit was reached, when the provider said so. An unknown value reads as absent."
}
},
"type": "object"
},
"ErrorKind": {
"enum": [
"auth_expired",
"rate_limited",
"context_overflow",
"transient",
"permanent"
],
"type": "string"
},
"FunctionResultMessage": {
"properties": {
"content": {
"items": {
"$ref": "#/definitions/ContentBlock"
},
"type": "array"
},
"details": true,
"function_call_id": {
"type": "string"
},
"function_id": {
"type": "string"
},
"is_error": {
"type": "boolean"
},
"role": {
"$ref": "#/definitions/FunctionResultRoleTag"
},
"timestamp": {
"format": "int64",
"type": "integer"
}
},
"required": [
"content",
"details",
"function_call_id",
"function_id",
"is_error",
"role",
"timestamp"
],
"type": "object"
},
"FunctionResultRoleTag": {
"enum": [
"function_result"
],
"type": "string"
},
"StopReason": {
"enum": [
"end",
"length",
"function_call",
"aborted",
"error"
],
"type": "string"
},
"ThinkingLevel": {
"description": "\"off\" asks the provider not to reason at all and is honoured only where the model advertises `Model::supports_thinking_off` (elsewhere the provider falls back to its own lowest setting, or omits the parameter, and warns). \"minimal\" requests the lowest reasoning effort and needs only `thinking` support; levels map to provider-native knobs via `Model::thinking_budgets`.",
"enum": [
"off",
"minimal",
"low",
"medium",
"high",
"xhigh"
],
"type": "string"
},
"Usage": {
"properties": {
"cache_read": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"cache_write": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"cost_usd": {
"format": "double",
"type": [
"number",
"null"
]
},
"input": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"output": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"reasoning": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
}
},
"type": "object"
},
"UsageWindow": {
"description": "The usage window an account's limit belongs to.",
"oneOf": [
{
"description": "The rolling five-hour window.",
"enum": [
"five_hour"
],
"type": "string"
},
{
"description": "The weekly window (any of the plan's seven-day limits).",
"enum": [
"week"
],
"type": "string"
}
]
},
"UserMessage": {
"properties": {
"content": {
"items": {
"$ref": "#/definitions/ContentBlock"
},
"type": "array"
},
"role": {
"$ref": "#/definitions/UserRoleTag"
},
"timestamp": {
"format": "int64",
"type": "integer"
}
},
"required": [
"content",
"role",
"timestamp"
],
"type": "object"
},
"UserRoleTag": {
"description": "Single-variant role tags: exact-match on deserialize, correct wire string on serialize, and they let `AgentMessage` be an untagged union.",
"enum": [
"user"
],
"type": "string"
}
},
"properties": {
"messages": {
"description": "Wire agent messages, the same shape `provider::claude-code::stream` accepts. Must be non-empty.",
"items": {
"$ref": "#/definitions/AgentMessage"
},
"type": "array"
},
"model": {
"description": "Model id the prompt targets (required by the upstream endpoint); a namespaced router id (`claude-code/<id>`) is mapped to the upstream id.",
"type": "string"
},
"system_prompt": {
"default": null,
"description": "System prompt counted as the second wire `system` block when present (the first is always the Claude Code identity line).",
"type": [
"string",
"null"
]
},
"thinking_level": {
"anyOf": [
{
"$ref": "#/definitions/ThinkingLevel"
},
{
"type": "null"
}
],
"default": null,
"description": "Reasoning level the turn would stream with; mapped to the same `thinking` / `output_config.effort` fields, which Anthropic renders into the prompt. Absent behaves like the stream's absent level."
},
"tools": {
"default": null,
"description": "Function invocation schemas; mapped to the wire `tools` array.",
"items": {
"$ref": "#/definitions/AgentFunction"
},
"type": [
"array",
"null"
]
}
},
"required": [
"messages",
"model"
],
"title": "CountTokensRequest",
"type": "object"
},
"response_schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"estimator": {
"description": "Always `provider`: the count came from the upstream metering API.",
"type": "string"
},
"model": {
"description": "Upstream model id the count was computed for.",
"type": "string"
},
"tokens": {
"description": "Prompt tokens the upstream endpoint counted for the assembled request.",
"format": "uint64",
"minimum": 0,
"type": "integer"
}
},
"required": [
"estimator",
"model",
"tokens"
],
"title": "CountTokensResponse",
"type": "object"
}
},
{
"description": "Internal: re-declares this provider and refreshes its catalog on every router::on-ready event.",
"metadata": {
"internal": true
},
"name": "provider::claude-code::on_router_ready",
"request_schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "The router's ready event: what `router::on-ready` returns, and what a provider's `provider::<id>::on_router_ready` receives. Currently `{}`; unknown fields are ignored.",
"title": "RouterReadyEvent",
"type": "object"
},
"response_schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Ack returned by a provider's `provider::<id>::on_router_ready`.",
"properties": {
"ok": {
"type": "boolean"
}
},
"required": [
"ok"
],
"title": "ProviderReadyAck",
"type": "object"
}
},
{
"description": "Refresh the Claude Code catalog slice from the upstream models endpoint and reconcile it through the router; returns the model count written.",
"metadata": {
"internal": true
},
"name": "provider::claude-code::refresh_models",
"request_schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Input of a provider's `provider::<id>::refresh_models` — takes no arguments. A struct (not `Value`) keeps the request schema concrete; unknown fields (e.g. the engine-injected `_caller_worker_id`) are ignored.",
"title": "RefreshModelsRequest",
"type": "object"
},
"response_schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Output of `provider::<id>::refresh_models`.",
"properties": {
"count": {
"format": "uint",
"minimum": 0,
"type": "integer"
},
"ok": {
"type": "boolean"
}
},
"required": [
"count",
"ok"
],
"title": "RefreshModelsResponse",
"type": "object"
}
},
{
"description": "Stream a Claude (subscription) chat completion: resolve credentials, call the upstream Messages API, and relay AssistantMessageEvent frames to writer_ref.",
"metadata": {
"internal": true
},
"name": "provider::claude-code::stream",
"request_schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"AgentFunction": {
"description": "Function invocation schema — what a provider sees as a `tools` array entry (README § Function invocation schema; adapter boundary). These describe iii functions exposed to the model, not provider-native tools.",
"properties": {
"description": {
"type": "string"
},
"execution_mode": {
"type": [
"string",
"null"
]
},
"label": {
"type": [
"string",
"null"
]
},
"name": {
"type": "string"
},
"parameters": true
},
"required": [
"description",
"name",
"parameters"
],
"type": "object"
},
"AgentMessage": {
"anyOf": [
{
"$ref": "#/definitions/AssistantMessage"
},
{
"$ref": "#/definitions/FunctionResultMessage"
},
{
"$ref": "#/definitions/CustomMessage"
},
{
"$ref": "#/definitions/UserMessage"
}
],
"description": "The canonical transcript message union. Untagged: the single-variant role tags disambiguate deserialization."
},
"AssistantMessage": {
"properties": {
"content": {
"items": {
"$ref": "#/definitions/ContentBlock"
},
"type": "array"
},
"error_details": {
"anyOf": [
{
"$ref": "#/definitions/ErrorDetails"
},
{
"type": "null"
}
],
"description": "What `error_kind` alone does not say, such as an account's usage limit. Omitted when absent; readers that don't know it ignore it."
},
"error_kind": {
"anyOf": [
{
"$ref": "#/definitions/ErrorKind"
},
{
"type": "null"
}
]
},
"error_message": {
"type": [
"string",
"null"
]
},
"model": {
"type": "string"
},
"native_stop_reason": {
"type": [
"string",
"null"
]
},
"provider": {
"type": "string"
},
"role": {
"$ref": "#/definitions/AssistantRoleTag"
},
"stop_reason": {
"$ref": "#/definitions/StopReason"
},
"timestamp": {
"format": "int64",
"type": "integer"
},
"usage": {
"anyOf": [
{
"$ref": "#/definitions/Usage"
},
{
"type": "null"
}
]
},
"warnings": {
"items": {
"type": "string"
},
"type": [
"array",
"null"
]
}
},
"required": [
"content",
"model",
"provider",
"role",
"stop_reason",
"timestamp"
],
"type": "object"
},
"AssistantRoleTag": {
"enum": [
"assistant"
],
"type": "string"
},
"ChannelDirection": {
"description": "Which end of a pipe a [`StreamChannelRef`] opens: `read` is received as an [`InputStream`](crate::InputStream), `write` as an [`OutputStream`](crate::OutputStream).",
"enum": [
"read",
"write"
],
"type": "string"
},
"ContentBlock": {
"description": "Content blocks — the atomic units of message content (README § Content blocks).",
"oneOf": [
{
"properties": {
"text": {
"type": "string"
},
"type": {
"enum": [
"text"
],
"type": "string"
}
},
"required": [
"text",
"type"
],
"type": "object"
},
{
"properties": {
"attachment_id": {
"description": "Optional link to the stored original in the session-manager attachment store. Transcript bookkeeping for lazy readers only: the harness clears it before `router::chat`, and no provider mapping reads it. Tolerated here so a block that still carries it deserializes instead of failing the request; omitted on the wire when absent.",
"type": [
"string",
"null"
]
},
"data": {
"type": "string"
},
"mime": {
"type": "string"
},
"type": {
"enum": [
"image"
],
"type": "string"
}
},
"required": [
"data",
"mime",
"type"
],
"type": "object"
},
{
"description": "Reference to an original upload in the session-manager attachment store. A REFERENCE ONLY (never inline bytes); the harness strips it before `router::chat`. Tolerated here so a stray block deserializes instead of failing the request; every counter/mapping emits nothing for it.",
"properties": {
"attachment_id": {
"type": "string"
},
"mime": {
"type": "string"
},
"name": {
"type": "string"
},
"size": {
"format": "uint64",
"minimum": 0,
"type": "integer"
},
"type": {
"enum": [
"file"
],
"type": "string"
}
},
"required": [
"attachment_id",
"mime",
"name",
"size",
"type"
],
"type": "object"
},
{
"properties": {
"signature": {
"type": [
"string",
"null"
]
},
"text": {
"type": "string"
},
"type": {
"enum": [
"thinking"
],
"type": "string"
}
},
"required": [
"text",
"type"
],
"type": "object"
},
{
"description": "Opaque redacted thinking payload — replayed verbatim on the Anthropic wire.",
"properties": {
"data": {
"type": "string"
},
"type": {
"enum": [
"redacted_thinking"
],
"type": "string"
}
},
"required": [
"data",
"type"
],
"type": "object"
},
{
"properties": {
"arguments": true,
"function_id": {
"type": "string"
},
"id": {
"type": "string"
},
"type": {
"enum": [
"function_call"
],
"type": "string"
}
},
"required": [
"arguments",
"function_id",
"id",
"type"
],
"type": "object"
},
{
"properties": {
"content": {
"items": {
"$ref": "#/definitions/ContentBlock"
},
"type": "array"
},
"function_call_id": {
"type": "string"
},
"is_error": {
"type": [
"boolean",
"null"
]
},
"type": {
"enum": [
"function_result"
],
"type": "string"
}
},
"required": [
"content",
"function_call_id",
"type"
],
"type": "object"
}
]
},
"CustomMessage": {
"properties": {
"content": {
"items": {
"$ref": "#/definitions/ContentBlock"
},
"type": "array"
},
"custom_type": {
"type": "string"
},
"details": true,
"display": {
"type": [
"string",
"null"
]
},
"role": {
"$ref": "#/definitions/CustomRoleTag"
},
"timestamp": {
"format": "int64",
"type": "integer"
}
},
"required": [
"content",
"custom_type",
"role",
"timestamp"
],
"type": "object"
},
"CustomRoleTag": {
"enum": [
"custom"
],
"type": "string"
},
"ErrorDetails": {
"description": "What an error's kind alone does not say. Optional on the assistant message and on the router's `ErrorShape`, and serialized only when present, so every reader that does not know it ignores it: `ErrorKind` itself keeps its five values, because its copies elsewhere deserialize it strictly.",
"properties": {
"resets_at_ms": {
"description": "When that limit resets, in milliseconds since the epoch.",
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"usage_limit": {
"default": false,
"description": "The account's usage limit is reached: a `rate_limited` that waiting a moment does not fix, so the router never retries it.",
"type": "boolean"
},
"window": {
"anyOf": [
{
"$ref": "#/definitions/UsageWindow"
},
{
"type": "null"
}
],
"description": "Which limit was reached, when the provider said so. An unknown value reads as absent."
}
},
"type": "object"
},
"ErrorKind": {
"enum": [
"auth_expired",
"rate_limited",
"context_overflow",
"transient",
"permanent"
],
"type": "string"
},
"FunctionResultMessage": {
"properties": {
"content": {
"items": {
"$ref": "#/definitions/ContentBlock"
},
"type": "array"
},
"details": true,
"function_call_id": {
"type": "string"
},
"function_id": {
"type": "string"
},
"is_error": {
"type": "boolean"
},
"role": {
"$ref": "#/definitions/FunctionResultRoleTag"
},
"timestamp": {
"format": "int64",
"type": "integer"
}
},
"required": [
"content",
"details",
"function_call_id",
"function_id",
"is_error",
"role",
"timestamp"
],
"type": "object"
},
"FunctionResultRoleTag": {
"enum": [
"function_result"
],
"type": "string"
},
"Model": {
"description": "The capability record (README § Model descriptor).",
"properties": {
"context_window": {
"format": "uint64",
"minimum": 0,
"type": "integer"
},
"display_name": {
"type": [
"string",
"null"
]
},
"id": {
"type": "string"
},
"input_limit": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"max_output_tokens": {
"format": "uint64",
"minimum": 0,
"type": "integer"
},
"pricing": {
"anyOf": [
{
"$ref": "#/definitions/Pricing"
},
{
"type": "null"
}
]
},
"provider": {
"type": "string"
},
"reasoning_efforts": {
"items": {
"$ref": "#/definitions/ReasoningEffort"
},
"type": [
"array",
"null"
]
},
"speech": {
"anyOf": [
{
"$ref": "#/definitions/SpeechModel"
},
{
"type": "null"
}
],
"description": "Set on speech models only; see [`SpeechModel`]."
},
"supports_cache": {
"type": [
"boolean",
"null"
]
},
"supports_structured_output": {
"type": [
"boolean",
"null"
]
},
"supports_thinking": {
"type": [
"boolean",
"null"
]
},
"supports_thinking_off": {
"description": "Whether `thinking_level: off` can switch the model's reasoning off. `Some(true)`: a native off switch exists. `Some(false)`: the model always reasons, or the provider has no switch. `None`: the provider does not know; consoles show the choice disabled.",
"type": [
"boolean",
"null"
]
},
"supports_tools": {
"type": [
"boolean",
"null"
]
},
"supports_vision": {
"type": [
"boolean",
"null"
]
},
"supports_xhigh": {
"type": [
"boolean",
"null"
]
},
"thinking_budgets": {
"additionalProperties": {
"format": "uint64",
"minimum": 0,
"type": "integer"
},
"type": [
"object",
"null"
]
}
},
"required": [
"context_window",
"id",
"max_output_tokens",
"provider"
],
"type": "object"
},
"Pricing": {
"properties": {
"cache_read": {
"format": "double",
"type": [
"number",
"null"
]
},
"cache_write": {
"format": "double",
"type": [
"number",
"null"
]
},
"input": {
"format": "double",
"type": [
"number",
"null"
]
},
"output": {
"format": "double",
"type": [
"number",
"null"
]
}
},
"type": "object"
},
"PromptCacheIntent": {
"description": "Why a request's stable prefix is shareable across sessions: `surface_digest` is the caller's content identity for the text before the boundary (`sha256:<hex>`). A routing/accounting hint only — never a provider cache handle, and never evidence of a cache hit.",
"properties": {
"surface_digest": {
"type": "string"
}
},
"required": [
"surface_digest"
],
"type": "object"
},
"PromptSection": {
"description": "One ordered system-prompt section. `cache_boundary` marks the end of a cumulative prefix worth its own provider cache entry (the frozen agent-profile surface). Adapters without a boundary concept read the sections joined with \"\\n\\n\", which must equal `system_prompt` when both forms are sent.",
"properties": {
"cache_boundary": {
"default": false,
"type": "boolean"
},
"text": {
"type": "string"
}
},
"required": [
"text"
],
"type": "object"
},
"ReasoningEffort": {
"description": "One provider-native reasoning effort advertised for a specific model.\n\nValues intentionally remain strings: provider catalogs can add efforts without requiring a router-wide enum release first.",
"properties": {
"description": {
"type": [
"string",
"null"
]
},
"effort": {
"type": "string"
}
},
"required": [
"effort"
],
"type": "object"
},
"ResponseFormat": {
"properties": {
"schema": true,
"type": {
"type": "string"
}
},
"required": [
"type"
],
"type": "object"
},
"SpeechModality": {
"description": "What a speech model does. Chat models carry no `speech` block.",
"oneOf": [
{
"description": "Speech to text, served through `router::transcribe`.",
"enum": [
"stt"
],
"type": "string"
},
{
"description": "Text to speech, served through `router::speak`.",
"enum": [
"tts"
],
"type": "string"
}
]
},
"SpeechModel": {
"description": "Facts about a speech model. Present only on models served through `router::transcribe` / `router::speak`; such models report `context_window` and `max_output_tokens` as 0.",
"properties": {
"languages": {
"description": "BCP-47 tags of the languages the model handles; empty when the provider does not say.",
"items": {
"type": "string"
},
"type": "array"
},
"modality": {
"$ref": "#/definitions/SpeechModality"
},
"streaming": {
"default": false,
"description": "Realtime input (stt) or streamed audio output (tts) is available.",
"type": "boolean"
}
},
"required": [
"modality"
],
"type": "object"
},
"StopReason": {
"enum": [
"end",
"length",
"function_call",
"aborted",
"error"
],
"type": "string"
},
"StreamChannelRef": {
"description": "One end of an engine pipe as a payload carries it: `{ channel_id, access_key, direction }`. The JSON is the same in every SDK and release, so new and old SDKs read each other's refs.",
"properties": {
"access_key": {
"type": "string"
},
"channel_id": {
"type": "string"
},
"direction": {
"$ref": "#/definitions/ChannelDirection"
}
},
"required": [
"access_key",
"channel_id",
"direction"
],
"type": "object"
},
"ThinkingLevel": {
"description": "\"off\" asks the provider not to reason at all and is honoured only where the model advertises `Model::supports_thinking_off` (elsewhere the provider falls back to its own lowest setting, or omits the parameter, and warns). \"minimal\" requests the lowest reasoning effort and needs only `thinking` support; levels map to provider-native knobs via `Model::thinking_budgets`.",
"enum": [
"off",
"minimal",
"low",
"medium",
"high",
"xhigh"
],
"type": "string"
},
"Usage": {
"properties": {
"cache_read": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"cache_write": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"cost_usd": {
"format": "double",
"type": [
"number",
"null"
]
},
"input": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"output": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"reasoning": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
}
},
"type": "object"
},
"UsageWindow": {
"description": "The usage window an account's limit belongs to.",
"oneOf": [
{
"description": "The rolling five-hour window.",
"enum": [
"five_hour"
],
"type": "string"
},
{
"description": "The weekly window (any of the plan's seven-day limits).",
"enum": [
"week"
],
"type": "string"
}
]
},
"UserMessage": {
"properties": {
"content": {
"items": {
"$ref": "#/definitions/ContentBlock"
},
"type": "array"
},
"role": {
"$ref": "#/definitions/UserRoleTag"
},
"timestamp": {
"format": "int64",
"type": "integer"
}
},
"required": [
"content",
"role",
"timestamp"
],
"type": "object"
},
"UserRoleTag": {
"description": "Single-variant role tags: exact-match on deserialize, correct wire string on serialize, and they let `AgentMessage` be an untagged union.",
"enum": [
"user"
],
"type": "string"
}
},
"description": "Input of a provider worker's `provider::<id>::stream` iii function — what the router forwards per attempt. (No `PartialEq`: `iii_sdk::StreamChannelRef` doesn't implement it.)",
"properties": {
"cache_intent": {
"anyOf": [
{
"$ref": "#/definitions/PromptCacheIntent"
},
{
"type": "null"
}
]
},
"max_output_tokens": {
"format": "uint64",
"minimum": 0,
"type": [
"integer",
"null"
]
},
"messages": {
"items": {
"$ref": "#/definitions/AgentMessage"
},
"type": "array"
},
"model": {
"type": "string"
},
"model_meta": {
"anyOf": [
{
"$ref": "#/definitions/Model"
},
{
"type": "null"
}
]
},
"provider_options": true,
"resolution_key": {
"type": [
"string",
"null"
]
},
"response_format": {
"anyOf": [
{
"$ref": "#/definitions/ResponseFormat"
},
{
"type": "null"
}
]
},
"session_id": {
"description": "Stable conversation identity for provider cache affinity.",
"type": [
"string",
"null"
]
},
"system_prompt": {
"type": [
"string",
"null"
]
},
"system_sections": {
"description": "Ordered sections behind `system_prompt` (always forwarded alongside the flat string, which equals the sections joined with \"\\n\\n\").",
"items": {
"$ref": "#/definitions/PromptSection"
},
"type": [
"array",
"null"
]
},
"thinking_level": {
"anyOf": [
{
"$ref": "#/definitions/ThinkingLevel"
},
{
"type": "null"
}
]
},
"tools": {
"items": {
"$ref": "#/definitions/AgentFunction"
},
"type": [
"array",
"null"
]
},
"writer_ref": {
"$ref": "#/definitions/StreamChannelRef"
}
},
"required": [
"messages",
"model",
"writer_ref"
],
"title": "ProviderStreamInput",
"type": "object"
},
"response_schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Output of a provider's `provider::<id>::stream` (spec § stream contract): the function streams frames to `writer_ref` and returns this ack.",
"properties": {
"ok": {
"type": "boolean"
}
},
"required": [
"ok"
],
"title": "ProviderStreamOutput",
"type": "object"
}
}
]
}