Skip to main content
To run OpenCode on LaoZhang API, add a custom provider in opencode.json with the base URL https://api.laozhang.ai/v1 and your LaoZhang API key.

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 use @ai-sdk/openai for GPT-6

@ai-sdk/openai uses the Responses API, where GPT-6 calls tools directly. The max reasoning effort for gpt-6.1-sol and web search (web_search) are also available only in Responses. @ai-sdk/openai-compatible uses Chat Completions and sends max_tokens. Before November 4, 2026, GPT-6 models rejected that parameter, and the request failed with:
LaoZhang API now accepts that parameter and handles tool calls in Chat Completions, so GPT-6 also works under laozhang-compat. 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.