Skip to content

opencode

View as Markdown

opencode calls Vikey through the OpenAI chat completions format.

Tested with opencode 1.19.5 (the latest release) on 13 November 2026.

  1. Keep the API key in an environment variable:

    Terminal window
    export VIKEY_API_KEY=YOUR_API_KEY
  2. Add the Vikey provider to ~/.config/opencode/opencode.jsonc (all projects) or opencode.jsonc in the project folder:

    ~/.config/opencode/opencode.jsonc
    {
    "$schema": "https://opencode.ai/config.json",
    "provider": {
    "vikey": {
    "npm": "@ai-sdk/openai-compatible",
    "name": "Vikey",
    "options": {
    "baseURL": "https://api.vikey.ai/v1",
    "apiKey": "{env:VIKEY_API_KEY}"
    },
    "models": {
    "vikey/agent-gpt": { "name": "Vikey Auto GPT" },
    "vikey/agent-coding": { "name": "Vikey Auto Claude" },
    "anthropic/claude-sonnet-5.5": { "name": "Claude Sonnet 5.5" },
    "openai/gpt-6.1-sol": { "name": "GPT-6.1 Sol" },
    "openai/gpt-6-luna": { "name": "GPT-6 Luna" }
    }
    }
    },
    "model": "vikey/vikey/agent-gpt",
    "small_model": "vikey/openai/gpt-6-luna"
    }
  3. Run opencode. Change models with the /models command.

Line Purpose
npm The adapter for OpenAI-compatible APIs. opencode downloads it automatically on first use.
options.baseURL With /v1.
options.apiKey {env:VIKEY_API_KEY} reads the key from the environment, so the key is not in the file.
models The models shown in /models. Each key must match a Vikey model id exactly.
model The default model, written provider-id/model-id. Vikey model ids also contain a slash, so it looks like vikey/vikey/agent-gpt or vikey/openai/gpt-6.1-sol.
small_model The model for small tasks such as session titles. Pick a cheap one so these cost almost nothing.

If you would rather not use an environment variable, remove the apiKey line from the config, run opencode, type /connect, choose Vikey and paste the API key. opencode keeps it in its own credential store.

Terminal window
opencode run "reply with the word ok"

On success opencode prints ok together with the model it used.

What you see Cause Fix
Model not found: vikey/... The model is not in models, or the unsupported providers format is used Add the model id to models and use the provider format
401 VIKEY_API_KEY is not exported in this terminal Export it again, or use /connect
Session titles use an expensive model small_model is not set Set small_model to a cheap model such as vikey/openai/gpt-6-luna