opencode

Written for opencode 1.18.34 (npm opencode-ai@latest, the V1 provider schema). opencode talks to zdr.sh over Chat Completions through its bundled @ai-sdk/openai-compatible provider.

Configure#

Put this in opencode.json, global at ~/.config/opencode/opencode.json or in the project. The key is read from the environment with {env:ZDR_API_KEY}.

json
{  "$schema": "https://opencode.ai/config.json",  "model": "zdr/glm-5.3",  "small_model": "zdr/glm-5.3-flash",  "provider": {    "zdr": {      "npm": "@ai-sdk/openai-compatible",      "name": "zdr.sh",      "options": {        "baseURL": "https://api.zdr.sh/v1",        "apiKey": "{env:ZDR_API_KEY}"      },      "models": {        "deepseek-v4.1-flash": {          "name": "DeepSeek V4.1 Flash",          "reasoning": true,          "interleaved": { "field": "reasoning_content" },          "limit": { "context": 1048576, "output": 393216 }        },        "glm-5.3": {          "name": "GLM 5.3",          "reasoning": true,          "interleaved": { "field": "reasoning_content" },          "limit": { "context": 1048576, "output": 131072 }        },        "glm-5.3-flash": {          "name": "GLM 5.3 Flash",          "reasoning": true,          "interleaved": { "field": "reasoning_content" },          "limit": { "context": 1048576, "output": 131072 }        }      }    }  }}

Then run opencode and pick a zdr/ model with /model, or start with opencode -m zdr/glm-5.3.

The parts that matter#

  • limit is required. opencode fails a model entry with a partial limit and treats an omitted one as 0/0, which disables compaction and long sessions. Both context and output are needed.
  • One id per model. The config key and the id are the model id, with no suffix.
  • interleaved. opencode strips reasoning from assistant history and sends it back in reasoning_content only when this is set. Set it on every model.
  • No model discovery. opencode never calls GET /v1/models for a custom provider, so the list above is the list you get. opencode models zdr prints it.
  • Effort variants. Define one by hand when you want a selector:
json
"glm-5.3": { "variants": { "high": { "reasoningEffort": "high" } } }

Auth without the environment#

Run opencode auth login, choose Other, enter the provider id zdr and paste the key; then remove options.apiKey. In the TUI the same flow is /connect. The stored key is used only when the config does not set one.