Providers

oi speaks four wire APIs natively over Zig's std.http client (TLS included) and SSE, with no SDKs. Every model resolves to one of them:

Wire API Endpoint Used for
anthropic-messages {base}/messages Anthropic, Claude models on OpenCode Zen, Anthropic-compatible gateways
openai-responses {base}/responses OpenAI, GPT models on OpenCode Zen
openai-completions {base}/chat/completions OpenRouter, xAI, Groq, DeepSeek, Mistral, Cerebras, open models on Zen, Ollama, LM Studio, vLLM, any OpenAI-compatible server
google-generative-ai {base}/models/{id}:streamGenerateContent?alt=sse Gemini API, Gemini models on OpenCode Zen

Catalog. Models are addressed as provider/model; a bare id resolves to its first-party provider. The catalog has three layers, and later ones override earlier ones:

  1. A built-in snapshot, which works offline: Anthropic, OpenAI, Google, DeepSeek, OpenCode Zen, OpenRouter, Ollama and LM Studio.
  2. The models.dev registry (327 providers), cached at ~/.cache/oi/models.json. Refresh it with oi models --refresh; it is also fetched once when you ask for an unknown model. OI_OFFLINE=1 disables fetching and OI_MODELS_URL points at a mirror.
  3. Your providers in config.

Like opencode, the AI SDK package that models.dev lists for each provider decides its wire API. Gateway entries can route each model differently: on OpenCode Zen, claude-* goes to /anthropic, GPT to /responses, Gemini to /google, and the rest to chat completions. Each model's context window, output limit, effort levels and $/MTok come from the same registry.

{ "model": "vllm/qwen3-coder",
  "providers": { "vllm": { "api": "openai-completions", "base_url": "http://gpu:8000/v1",
      "api_key": { "env": "VLLM_KEY" }, "headers": { "X-Team": "infra" },
      "models": { "qwen3-coder": { "context": 262144, "max_output": 32768, "reasoning": true,
                                   "cost": { "input": 0.5, "output": 1.5 } } } } } }

Credentials. They are resolved in this order:

  1. The provider's api_key ref from config ({env} or {keychain}; plaintext is rejected).
  2. The provider's env vars from models.dev (e.g. GEMINI_API_KEY, OPENROUTER_API_KEY).
  3. oi secret set <provider>.

Two exceptions:

  • Loopback servers (Ollama, LM Studio) need no key.
  • OpenCode Zen without a key uses its public free tier, which only allows free models.

ANTHROPIC_BASE_URL, OPENAI_BASE_URL and GOOGLE_GEMINI_BASE_URL override endpoints. There is no subscription OAuth (Claude Pro/Max, ChatGPT/Codex, Copilot): in the harnesses I studied, those flows work by presenting as the vendor's own client (its OAuth client id, user agent, or system prompt).

Per-provider request details:

  • Anthropic: adaptive thinking with summarized display, output_config.effort, eager_input_streaming tools, and server-side refusal fallbacks on models that support them. Prompt caching is described below.
  • OpenAI Responses: store:false with encrypted reasoning (include: ["reasoning.encrypted_content"]) and reasoning.summary:"auto".
  • Chat Completions:
    • Per-host compatibility covers max_completion_tokens vs max_tokens, the developer role, reasoning_effort vs OpenRouter's reasoning.effort, and store.
    • Requests send stream_options.include_usage.
    • Reasoning comes from reasoning_content, reasoning or reasoning_text.
  • Gemini: thinkingConfig (a thinkingLevel when the model lists levels, otherwise a dynamic budget), and parametersJsonSchema with meta keywords and dangling required entries removed.
  • All APIs:
    • Effort (--effort) is clamped to the levels each model accepts.
    • Usage is normalized to input (including cache), cache read/write and output.
    • Cost comes from catalog prices, unless a gateway reports a billed cost.

Prompt caching. Every provider caches on an exact prefix of the request (tools, then system, then messages), so oi keeps that prefix byte-stable for a whole session:

  • The system prompt does not change mid-session: its date is the session's start date.
  • The tool list is deterministic: core tools first, then agent, then the meta tools, then plugin tools sorted by name, serialized with sorted keys. Agent profiles load at start (and on /reload), so the agent tool's description does not change mid-session.
  • Forked sub-agents reuse the parent's cache: a context: "fork" child sends the parent's system prompt, tools and history byte for byte, then its task.
  • History is append-only: every request extends the previous one, and compaction appends a summary event instead of rewriting.
  • Compaction reads the cache: its request reuses the loop's exact system prompt, tools and history, and appends the summarize instruction at the end.
  • tool_search activations don't invalidate the cache on current Claude models (Opus 5.5, Fable 5.x, Sonnet 5.5, Haiku 5.5, …). tools[] stays as first sent, and each activated tool arrives as a tool_addition block in a system message at the point in history where it was found (beta inline-tools-2026-09-15). Other providers get the full, sorted tool list.

zig build e2e checks all of this on real multi-step sessions: tools and system byte-identical, and each request a strict prefix-extension of the previous one.

Per provider:

Provider What oi sends
Anthropic An explicit breakpoint on the system block (a guaranteed read point for tools + system), plus top-level automatic caching for the conversation tail.
OpenAI (Responses and Chat Completions) prompt_cache_key set to the session id.
OpenRouter anthropic/*, and Claude proxies marked "cache_control": true in config Anthropic-style markers on the system prompt and the last user message.
Gemini, DeepSeek and other providers with automatic prefix caching Nothing extra; they benefit from the stable prefix.

prompt_cache in config is 5m (default), 1h or off.

  • 5m suits agent loops whose requests are less than 5 minutes apart.
  • 1h suits sessions with longer pauses between turns. It sets ttl: "1h" on both Anthropic markers, and prompt_cache_retention: "24h" on OpenAI.

The turn footer shows the cache-hit share, e.g. 4.0k in / 49 out · 40% cached · $0.0087.

Switching models mid-session (-m, /model in the terminal UI, the ACP model config option, or "model" on POST /session/{id}/prompt) is safe. Sub-agents can run on a different model from their parent (a profile's model). History is stored once in a canonical, Anthropic-shaped form. Each assistant turn records which API, provider and model produced it, and each adapter converts the history when it builds a request:

  • Opaque reasoning goes back only to the model that wrote it. That covers Anthropic thinking signatures and redacted thinking, OpenAI encrypted reasoning items and item ids, chat-completions reasoning fields, and Gemini thought signatures. A different model gets the visible text and tool calls, never the reasoning.
  • Tool-call ids are mapped deterministically per wire format (Anthropic's [A-Za-z0-9_-]{1,64}, OpenAI's 40-character limit), and every result follows its call.
  • Gemini function calls written by another model carry Google's skip_thought_signature_validator sentinel.
  • Resuming: -c continues on the model the session last used.