Skip to content

Coding tools

OpenCode

Define Deference as a provider in opencode.json.

OpenCode loads OpenAI-compatible providers through @ai-sdk/openai-compatible. It speaks Chat Completions, so the base URL is https://deference.si/v1. This guide uses the 1.x config format.

Set up

  1. Create a key in API keys and export it as DEFERENCE_API_KEY in the shell that starts OpenCode.
  2. Add the provider to opencode.json in your project, or to ~/.config/opencode/opencode.json for every project. On Windows the global file is %USERPROFILE%\.config\opencode\opencode.jsonc.
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "deference": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Deference",
      "options": {
        "baseURL": "https://deference.si/v1",
        "apiKey": "{env:DEFERENCE_API_KEY}"
      },
      "models": {
        "anthropic/claude-sonnet-5.5": {
          "name": "Claude Sonnet 5.5",
          "limit": { "context": 200000, "output": 64000 }
        }
      }
    }
  },
  "model": "deference/anthropic/claude-sonnet-5.5"
}
  1. Start opencode.

To store the key instead of reading it from the environment, run /connect, choose Other, enter the provider id deference and paste the key. OpenCode saves it in ~/.local/share/opencode/auth.json.

Verify

  1. Run opencode models deference. It lists the models you declared.
  2. Run a one-off prompt.
opencode run -m deference/anthropic/claude-sonnet-5.5 \
  "Reply with exactly: gateway-ok"
  1. Open Activity. The request is the top row, with the model you chose.

opencode auth list shows keys saved with /connect. A key read from {env:DEFERENCE_API_KEY} does not appear there.

Pick a model

  • List each model you want under models, keyed by its exact id. Select one with -m deference/<id>, the model setting, or /models.
  • A model reference is provider/model. OpenCode splits on the first slash, so the model id can contain slashes.
  • Set limit.context and limit.output for every model. OpenCode takes limits from a public registry for its built-in providers and has none for yours.
  • Use @ai-sdk/openai as the package for models served through POST /v1/responses. You can set a different package on one model.
  • OpenCode 2 renames some config fields. Keep to one format per file and follow OpenCode's migration guide when you move.

Troubleshooting

You seeCauseFix
ProviderModelNotFoundErrorThe reference is not provider/model, or the model is not under modelsRun opencode models and copy the reference
The model is not in the listIt is missing from modelsAdd it, keyed by its exact id
401 missing_api_keyThe variable is not set where OpenCode starts, so the key is emptyExport DEFERENCE_API_KEY in that shell
The config is ignoredThe file is not valid JSONCheck commas and quotes
AI_APICallError after an upgradeOpenCode cached an old provider packageDelete ~/.cache/opencode and restart
404 model_not_foundThe key under models differs from the catalog idCopy the id from the Models page