TemprTempr
Docs
Guides

OpenCode

Last updated

OpenCode (terminal and desktop) already knows Tempr: Tempr Gateway is in its built-in model catalog, so every Gateway model (Claude, GPT, Gemini) shows up under tempr/ as soon as OpenCode has your virtual key. OpenCode 1 and 2 both work this way, and the same setup serves the CLI and the desktop app.

  1. Create a virtual key

    In the Portal, create a Gateway virtual key. Keys are prefixed tvk_ and shown once at creation.

  2. Add a provider key

    Gateway is BYOK: add a key for at least one provider from the supported list.

  3. Give OpenCode the key

    Run /connect in OpenCode (or opencode auth login tempr in a terminal), choose Tempr Gateway and paste the key. Or set TEMPR_API_KEY in the environment OpenCode starts from. Until you do one or the other, OpenCode sends no key, and Tempr answers every request with 401 missing_api_key.

    Paste the virtual key (tvk_...) here, not a provider's key: provider keys go in the Portal. A key saved with /connect stays until you replace it: run /connect again, or remove it with opencode auth logout tempr. If you set TEMPR_API_KEY, restart OpenCode, the desktop app included: it reads the environment only when it starts.

  4. Pick a model

    Choose one under Tempr Gateway with /models, or pass it with --model, such as tempr/anthropic/claude-sonnet-4-5. opencode models lists them all. The examples here use Anthropic models, which need an Anthropic key in the Portal; with another provider's key, use one of its models, or any model from GET /v1/models.

Settings in opencode.json

To keep the key and your models in opencode.json (project root or ~/.config/opencode/opencode.json), name the provider tempr. OpenCode fills in Tempr's address and model list from its catalog:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "tempr": {
      "options": { "apiKey": "{env:TEMPR_API_KEY}" }
    }
  },
  "model": "tempr/anthropic/claude-sonnet-4-5",
  "small_model": "tempr/anthropic/claude-haiku-4-5"
}

OpenCode 2 reads this format too. small_model is the model OpenCode uses for short background requests, such as session titles. Without it, OpenCode picks one from Tempr's list, such as google/gemini-flash-lite-latest, and those requests fail if you have no key for that provider.

Model ids

A Tempr model's id is tempr/ and the fully-qualified provider/model form, such as tempr/openai/gpt-5: the same ids GET /v1/models returns. To use one that isn't in OpenCode's catalog yet, add it under models in the provider's settings, keyed by its provider/model id: "models": { "openai/gpt-5": { "name": "GPT-5" } }.

Model discovery plugins

OpenCode lists Tempr's models without one. If you use a discovery plugin anyway, give it your virtual key as well: a request without one gets 401 missing_api_key, and the plugin then finds no models. Tempr doesn't serve LiteLLM's /v1/model/info, so leave a plugin's LiteLLM metadata option off.

On a coding plan

To run OpenCode on a coding plan, such as the Z.AI GLM Coding Plan or Kimi Code, use one of the plan's models, named by the plan: zai-coding/glm-5.3. Tempr can get the plan's key two ways:

  • Stored in Tempr. Add the plan's key under Provider keys in the Portal, and keep OpenCode's settings as they are, with your virtual key.
  • Sent with each request. Set the provider's apiKey to the plan's key and put your virtual key in headers as x-tempr-key. Leave Authorization out of headers: OpenCode sends the API key in it. Tempr sends the plan's key only to that plan, and never stores it. An organization's keys take a key sent this way once an owner or admin turns on Plan logins.
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "tempr": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://api.temprhq.io/v1",
        "apiKey": "{env:PLAN_KEY}",
        "headers": { "x-tempr-key": "{env:TEMPR_API_KEY}" }
      },
      "models": { "zai-coding/glm-5.3": { "name": "GLM 5.3" } }
    }
  },
  "model": "tempr/zai-coding/glm-5.3"
}

Several plans are sold only for the coding tools they support, and some refuse other tools, telling them apart by the identity each tool sends. Tempr passes OpenCode's own along and never sends another, so check which tools each plan supports before you subscribe.

Ask OpenCode about your Gateway

OpenCode can also read your Gateway through the Gateway's own MCP server: usage and cost, request logs and one request's routing, keys, plan, and providers cooling down. Ask it "why did my last few requests fail?" or "which key spent the most this week?" while you work. It comes with the Gateway Pro, Scale and Enterprise plans.

The quickest way is to sign in. Add the server to opencode.json, then run opencode mcp auth tempr-gateway, which opens Tempr's sign-in in the browser:

{
  "mcp": {
    "tempr-gateway": {
      "type": "remote",
      "url": "https://api.temprhq.io/mcp/admin"
    }
  }
}

Signed in this way, OpenCode reads your own Gateway, or your organization's if you're an owner or admin. To let it make changes too, tick Also let it make changes on Tempr's consent page.

To give it a management key instead:

  1. Create a management key

    In the Portal, under Gateway → Keys → Management keys (or Organization → Org keys for an organization's Gateway). A management key reads and manages the Gateway but can't call models, so it's separate from the tvk_ virtual key OpenCode uses for its model. Tick what OpenCode may do: Read usage, Read request logs and List keys to read; Create, change and revoke keys as well if it may change keys.

  2. Send the key, and have OpenCode ask first

    Put the key in TEMPR_MANAGEMENT_KEY and send it as a bearer token, with oauth off. OpenCode runs MCP tools without asking unless told otherwise, so the permission rule makes it ask before each Gateway tool:

{
  "mcp": {
    "tempr-gateway": {
      "type": "remote",
      "url": "https://api.temprhq.io/mcp/admin",
      "oauth": false,
      "headers": { "Authorization": "Bearer {env:TEMPR_MANAGEMENT_KEY}" }
    }
  },
  "permission": { "tempr-gateway_*": "ask" }
}
  • The key's permissions decide the tools. Without Read request logs, OpenCode gets the usage, plan and key tools but not the logs.
  • Changes also need the account to allow them: turn on Changes by AI agents on the Portal's MCP connectors page. OpenCode can then make changes that only tighten, such as creating a key that expires within 90 days or revoking one, and propose any that would loosen, such as a higher budget, for you to approve in the Portal. A new key's secret never reaches it: it gets a one-time Portal link for you to copy the key from.

What's next