llmboxDocumentationSign in
Integrations · OpenCode

OpenCode

Connecting OpenCode 2 and OpenCode 1 to the gateway through an OpenAI-compatible provider in opencode.jsonc or opencode.json.

OpenCode works through /v1/chat/completions in the OpenAI format. The setup below is for OpenCode 2; if you installed the opencode-ai npm package, you have OpenCode 1, which uses a different config format — see OpenCode 1. For an overview and model pricing, see OpenCode on llmbox.

Quick start

Install OpenCode 2:

bash
curl -fsSL https://opencode.ai/v2/install | bash
# or
npm install -g @opencode/cli

Put your key from the cabinet in the LLMBOX_API_KEY environment variable — OpenCode reads it from the variable named in the provider's env:

bash
export LLMBOX_API_KEY="your-key"

Add the provider to ~/.config/opencode/opencode.jsonc (or to opencode.jsonc in a project root — then the setting applies only there):

json
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "llmbox": {
      "name": "llmbox",
      "env": ["LLMBOX_API_KEY"],
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": { "baseURL": "https://llmbox.cc/v1" },
      "models": {
        "openai/gpt-6.1-sol": { "name": "GPT-6.1 Sol" },
        "deepseek/deepseek-v4-pro": { "name": "DeepSeek V4 Pro" }
      }
    }
  },
  "model": "llmbox/openai/gpt-6.1-sol"
}

Run opencode. The llmbox provider name is arbitrary; the model is set as llmbox/<catalog ID>.

Choosing a model

List the IDs from the model catalog you want to use under models — OpenCode shows them in the /models command. The model field sets the default.

How it works

  • OpenCode sends requests to /v1/chat/completions with the key from the environment variable; usage shows up in the cabinet.
  • OpenCode's tools (reading and editing files, shell commands) are your own functions — the gateway passes them to the model as is.
  • Every agent step is a separate request with the full session history, so long tasks use noticeably more input tokens than a chat.

OpenCode 1

OpenCode 1 (the opencode-ai npm package) reads ~/.config/opencode/opencode.json (or opencode.json in a project root) with a different schema: providers live under provider, the package is set with npm, and the address and key go into options. The key comes from the same LLMBOX_API_KEY variable:

json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "llmbox": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "llmbox",
      "options": {
        "baseURL": "https://llmbox.cc/v1",
        "apiKey": "{env:LLMBOX_API_KEY}"
      },
      "models": {
        "openai/gpt-5.6-sol": { "name": "openai/gpt-5.6-sol" }
      }
    }
  },
  "model": "llmbox/openai/gpt-5.6-sol"
}

Models, the /models command and the model field work the same way as in OpenCode 2.

Troubleshooting

SymptomCause and fix
The model is missing from /modelsIt is not listed under the llmbox provider's models — add its ID.
401 invalid_api_keyLLMBOX_API_KEY is not set in this terminal, or the key is revoked.
404 model_not_foundThe model ID has a typo — check GET/v1/models.
The llmbox provider does not show upThe config schema does not match your version: OpenCode 2 reads providers from opencode.jsonc, OpenCode 1 reads provider from opencode.json.