Skip to main content

OpenCode CLI

OpenCode is an open-source terminal AI coding agent. It works excellently with Openference.

Add the provider

Create or edit ~/.config/opencode/opencode.json:
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "openference": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Openference",
      "options": {
        "baseURL": "https://api.openference.com/v1",
        "apiKey": "{env:OPENFERENCE_API_KEY}"
      },
      "models": {
        "your-model-name": {
          "name": "Your Model (via Openference)"
        }
      }
    }
  }
}

Authenticate and connect

export OPENFERENCE_API_KEY="sk-token-YOUR_KEY_HERE"
opencode auth login   # choose Other, provider ID: openference
opencode
# inside the TUI run: /connect openference
You can also set the key directly in the config using the {env:...} syntax (shown above).

Verify flow

OpenCode connects by calling GET /v1/models and /v1/chat/completions. Openference returns an OpenAI-compatible model list filtered by key restrictions.

Model configuration

Add only the models you use. The model keys must match exactly the IDs shown on the Models page or returned by the API.

Notes

  • Both build and plan agents work through Openference.
  • You can switch agents with Tab and use /undo and /redo freely.
  • See the Compatibility Matrix for an overview of all clients.