> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laozhang.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenCode setup with LaoZhang API

> Add LaoZhang API to opencode.json: @ai-sdk/openai for GPT-6 and @ai-sdk/openai-compatible for DeepSeek, Gemini, and other models.

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.

| Item | Details |
| - | - |
| Global config file | `~/.config/opencode/opencode.json` |
| `baseURL` | `https://api.laozhang.ai/v1` |
| Package for OpenAI models | `@ai-sdk/openai` |
| Package for other models | `@ai-sdk/openai-compatible` |
| Recommended models | `gpt-6-sol`, `deepseek-v4-pro` |
| Last verified | October 5, 2026, OpenCode 1.18.34 |

## Install OpenCode

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

```bash theme={null}
npm install -g opencode-ai
opencode --version
```

## Configure LaoZhang API

<Steps>
  <Step title="Set the key as an environment variable">
    ```bash theme={null}
    echo 'export LAOZHANG_API_KEY="YOUR_LAOZHANG_API_KEY"' >> ~/.zshrc
    source ~/.zshrc
    ```

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

  <Step title="Write opencode.json">
    Create or edit `~/.config/opencode/opencode.json`. To apply it to one project only, put the file in the project root.

    ```json theme={null}
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "laozhang": {
          "npm": "@ai-sdk/openai",
          "name": "LaoZhang API",
          "options": {
            "baseURL": "https://api.laozhang.ai/v1",
            "apiKey": "{env:LAOZHANG_API_KEY}"
          },
          "models": {
            "gpt-6-sol": { "name": "GPT-6 Sol" },
            "gpt-5.4-mini": { "name": "GPT-5.4 mini" }
          }
        },
        "laozhang-compat": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "LaoZhang API (compatible)",
          "options": {
            "baseURL": "https://api.laozhang.ai/v1",
            "apiKey": "{env:LAOZHANG_API_KEY}"
          },
          "models": {
            "deepseek-v4-pro": { "name": "DeepSeek V4 Pro" },
            "gemini-3.8-flash": { "name": "Gemini 3.8 Flash" },
            "qwen3-coder-plus": { "name": "Qwen3 Coder Plus" }
          }
        }
      },
      "model": "laozhang/gpt-6-sol"
    }
    ```

    Keys under `models` must be full model IDs; `name` is only for display. `model` takes the form "provider/model ID".
  </Step>

  <Step title="Send a test request">
    ```bash theme={null}
    opencode run "Reply with exactly one word: connected"
    ```

    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`.
  </Step>
</Steps>

## 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:

```text theme={null}
Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.
```

`@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](/en/faq/invalid-api-key).

### 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](/en/scenarios#before-you-pick-a-model).

## Related pages

* [Integrations overview](/en/scenarios)
* [Model catalog](/en/models)
* [OpenCode providers docs](https://opencode.ai/docs/providers)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.