Skip to content

opencode

Add one provider to opencode's configuration and every call it makes is governed: checked against your policies, charged to your team and recorded in Request logs. opencode reaches the gateway in the OpenAI format, and the gateway translates that format to every provider, so opencode can work with Claude or Gemini models as well as GPT.

What it is

opencode is an open-source coding agent for the terminal (with desktop and IDE front ends). It reads and edits the files in your project and runs commands, asking a model what to do next at each step. Models come from providers in its configuration; a custom provider points at any OpenAI-compatible address. It calls the gateway from your machine.

The settings

In opencode.json (in your project, or ~/.config/opencode/opencode.json for every project), add a provider:

{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "vidai": {
      "name": "Vidai",
      "package": "@opencode/ai/providers/openai-compatible",
      "env": ["VIDAI_API_KEY"],
      "settings": { "baseURL": "{env:VIDAI_BASE_URL}" },
      "models": {
        "gpt-4.1": { "name": "GPT-4.1", "limit": { "context": 1047576, "output": 32768 } },
        "claude-sonnet-4.5": { "name": "Claude Sonnet 4.5", "limit": { "context": 200000, "output": 64000 } }
      }
    }
  }
}

Then set the address and the key in your shell:

export VIDAI_BASE_URL="https://<your-gateway>/v1"
export VIDAI_API_KEY="vk_…"
Setting Value
package @opencode/ai/providers/openai-compatible (Chat Completions, /v1/chat/completions)
settings.baseURL https://<your-gateway>/v1, with /v1
env The variable that holds your Vidai key; opencode sends it as Authorization: Bearer
models One entry per model, keyed by the name the gateway knows

The gateway's address is under Connect your app on the Keys page and in System › Settings › Gateway; the key comes from Keys › Issue a key (its secret is shown once). The key starts vk_; never use a provider's key.

This is the configuration of opencode 2. A provider written the opencode 1 way, with "npm": "@ai-sdk/openai-compatible" and "options", is refused by opencode 2 as an unsupported package: move it to the shape above.

A minimal call

opencode run -m vidai/gpt-4.1 "Reply with exactly: ok"

The part before the slash is the provider's key in your configuration (vidai), the part after it a model you listed. In the terminal interface, pick the model with /models.

Streaming

opencode streams every step. A stream from Claude or Gemini arrives as OpenAI chunks; Vidai records tokens and cost either way.

Tool calls

opencode's steps (read a file, edit it, run a command) are tool calls. They work across providers: an OpenAI-format tool call reaches Claude or Gemini, and the answer comes back in the shape opencode expects. Use a model that is good at tool use; small models tend to stall on long tasks.

Reading what the gateway did

opencode doesn't show response headers. Look the calls up in Request logs: filter on Key, Model or Path (/v1/chat/completions). One task usually shows as many calls, one per step.

Errors

opencode prints the gateway's error message on the step that failed. Common ones while setting up: 401 invalid_api_key (the key is wrong, unset, or a provider's key), 403 model_not_allowed (your key may not call that model), 404 model_not_found (check the model's key in models), 403 content_guardrail_blocked (a guardrail stopped the content), 429 (a limit on the key or team). The full list is in Headers and errors.

Model names

The keys under models are the names the gateway sees: use the names your organisation approved under Models in the Control room. GET https://<your-gateway>/v1/models with your key lists exactly the models it may call. Add each model you want to the configuration, with its context and output limit (opencode uses them to decide when to compact a long session).

What goes through the gateway

opencode feature Through the gateway
Every step of a task, in the terminal, desktop or IDE Yes
MCP servers you add to opencode The model calls that use their tools, yes; the MCP servers themselves are reached directly by opencode

Check it works in a minute

Run the minimal call above, then open Request logs a few seconds later and filter on your key: the call is there, with its model, its team and its cost.

Good to know

  • Autonomous tasks are chatty: one task can be dozens of calls. Set a limit on the key (or the team's budget) so a runaway task stops at a known cost.
  • Issue one key per developer, so Request logs and cost reports show whose opencode made each call.
  • The cost opencode shows is its own estimate from the cost you give a model, or nothing; Vidai prices every call itself, in Request logs.
  • opencode's docs: Providers, Config.