# Use BigModel.io with OpenCode

> Add BigModel.io to OpenCode as an OpenAI-compatible provider in opencode.json with baseURL https://bigmodel.io/v1, set context limits for GLM, Kimi and DeepSeek, and fix common errors.

Web version: https://bigmodel.io/docs/opencode · Updated 2026-10-18

OpenCode supports any OpenAI-compatible API through the `@ai-sdk/openai-compatible` provider. It calls `/v1/chat/completions`, so it works with every BigModel.io group that serves text models, including Chat Completions-only GLM and DeepSeek groups.

| Setting | Value |
|---|---|
| `npm` | `@ai-sdk/openai-compatible` |
| `options.baseURL` | `https://bigmodel.io/v1` |
| `options.apiKey` | `{env:BIGMODEL_API_KEY}` |
| `models` | model IDs from the [model catalog](https://bigmodel.io/models) |
| `limit.context` / `limit.output` | the model's context window and max output, from its model page |

## Configure opencode.json

Put this in `~/.config/opencode/opencode.json` (all projects) or `opencode.json` in a project root:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "bigmodel": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "BigModel.io",
      "options": {
        "baseURL": "https://bigmodel.io/v1",
        "apiKey": "{env:BIGMODEL_API_KEY}"
      },
      "models": {
        "glm-5.3": { "name": "GLM-5.3" },
        "glm-5.3-flash": { "name": "GLM-5.3 Flash" },
        "kimi-k3": { "name": "Kimi K3" },
        "deepseek-v4-pro": { "name": "DeepSeek V4 Pro" }
      }
    }
  },
  "model": "bigmodel/glm-5.3",
  "small_model": "bigmodel/glm-5.3-flash"
}
```

Each key under `models` must be the exact model ID; `name` is only the label OpenCode shows. `{env:BIGMODEL_API_KEY}` reads the key from your environment, so the file is safe to share. `model` and `small_model` use the `provider/model` form; `small_model` handles light tasks such as titles.

```bash
export BIGMODEL_API_KEY="sk-..."
opencode
```

### Set context limits

OpenCode does not know the context window of a custom model. Add `limit` to each model so it compacts history at the right point. Take the numbers from the model page; the values below are placeholders:

```json
"glm-5.3": {
  "name": "GLM-5.3",
  "limit": { "context": 128000, "output": 16000 }
}
```

## Store the key with /connect instead

If you prefer not to use an environment variable, run `/connect` in OpenCode, choose **Other**, enter the provider ID `bigmodel` and paste your key. OpenCode stores it in `~/.local/share/opencode/auth.json`. Then remove `apiKey` from `options`.

## Verify the setup

Run `/models` inside OpenCode. The BigModel.io models from your config should be listed. Pick one, send a short prompt, and check that the request appears in [Usage](https://bigmodel.io/usage).

## Troubleshooting

**The BigModel.io provider does not appear in `/models`.** The JSON is invalid or in the wrong place. Validate it, and check that a project `opencode.json` is not replacing your global file.

**401 `API_KEY_REQUIRED`.** `BIGMODEL_API_KEY` is empty in the shell that started OpenCode, or the provider ID used with `/connect` does not match the key under `provider`.

**503 `api_error`: `No available accounts: no available accounts supporting model: ...`.** The key under `models` does not match a model your key's group serves. Copy the ID from the model page.

**404 on every request.** `baseURL` is missing `/v1` or has an extra `/chat/completions`.

**Long sessions fail or get cut off.** `limit.context` is unset or too large. Set it to the model's real context window.

**Tool calls fail or loop.** Some models handle long agent sessions better than others. Try a different model, and keep the first task small.

**403 `INSUFFICIENT_BALANCE` or 429.** Top up in [Billing](https://bigmodel.io/purchase). A 429 `rate_limit_error` ("Too many pending requests") means too many parallel requests; wait and retry.

## Related

- [Configure Base URL in Codex, Claude Code, Cursor and Cline](https://bigmodel.io/blog/configure-base-url-codex-claude-code-cursor)
- [Claude Code](https://bigmodel.io/docs/claude-code) and [Codex CLI](https://bigmodel.io/docs/codex-cli), the other terminal agents.
- [Migrate from OpenRouter](https://bigmodel.io/docs/migrate-from-openrouter) if your config uses `provider/model` names.
