Nbility logoNbility Docs

Search documentation

Search guides and API reference content

OpenCode is a terminal-oriented AI coding tool. To route it through Nbility, use environment variables plus an opencode.json configuration file.

Install OpenCode

Choose the installation command for your platform:

npm install -g opencode-ai@latest
brew install opencode
scoop install opencode

Prepare a Token

Go to /console/token, create an API Key, and make sure the token is still active.

Configure Environment Variables

Put the token into an environment variable first:

export NBility_TOKEN=sk-xxx
$env:NBility_TOKEN="sk-xxx"

Replace sk-xxx with your own Nbility Token.

Write opencode.json

Create opencode.json in your project root or under ~/.config/opencode/. If you want to connect both Claude and GPT model groups, use this structure:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "nbility-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "nbility-anthropic",
      "options": {
        "baseURL": "https://api.nbility.dev",
        "apiKey": "{env:NBility_TOKEN}"
      },
      "models": {
        "claude-sonnet-4-6": {
          "name": "claude-sonnet-4-6"
        }
      }
    },
    "nbility-openai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "nbility-openai",
      "options": {
        "baseURL": "https://api.nbility.dev/v1",
        "apiKey": "{env:NBility_TOKEN}"
      },
      "models": {
        "gpt-5.2-codex": {
          "name": "gpt-5.2-codex"
        }
      }
    }
  }
}

Important: The environment variable name and value in the example must match your local setup. Do not leave the token as placeholder text.

Start OpenCode

After configuration, enter your project and run:

cd my-project
opencode

In the interface, choose the Nbility provider and model you defined to start chatting or coding.

Tips

  • If you only use one model group, remove the other provider to reduce noise
  • If configuration fails, first check whether the environment variable is active in the current shell session
  • For quick troubleshooting, start with the simplest single-model configuration, then add more models gradually