Skip to main content
OpenCode connects to LaoZhang API through a custom provider in opencode.json. GPT-6 and other OpenAI models use the OpenAI package and the Responses API; DeepSeek, Gemini, Qwen, and others use the OpenAI-compatible package. Both fit in one config.

Install OpenCode

Install it globally with npm (Node.js required):

Configure LaoZhang API

1

Set the key as an environment variable

Use ~/.bashrc for bash. The config refers to it as {env:LAOZHANG_API_KEY}, so the key never goes into the file.
2

Write opencode.json

Create or edit ~/.config/opencode/opencode.json. To apply it to one project only, put the file in the project root.
Keys under models must be full model IDs; name is only for display. model takes the form “provider/model ID”.
3

Send a test request

Run opencode in a project directory for the interactive interface, and type /models to switch models. In non-interactive mode, pick a model with -m laozhang-compat/deepseek-v4-pro.

Why GPT-6 needs @ai-sdk/openai

@ai-sdk/openai-compatible uses Chat Completions and sends max_tokens. GPT-6 models reject that parameter, so the request fails with:
@ai-sdk/openai uses the Responses API, which avoids the problem and lets GPT-6 call tools directly. DeepSeek, Gemini, Qwen, and similar models accept max_tokens, so they work under @ai-sdk/openai-compatible.

FAQ

LaoZhang API models don’t appear after startup

Make sure opencode.json is valid JSON (a trailing comma breaks the whole file) and is in the right place. Restart OpenCode after changing the config.

I get a 401

In the terminal you run OpenCode from, run test -n "$LAOZHANG_API_KEY" && echo set to confirm the variable is set. If it still fails, see Invalid API key or 404.

Which other models can I add?

Any text model whose endpoints in the catalog include OpenAI-compatible can go under laozhang-compat. For coding, pick a model that calls tools reliably; see Before you pick a model.