OpenCode coding agent on SovereignEG

Goal: run OpenCode (an open-source terminal coding agent, similar to Claude Code) with SovereignEG as the model provider.

Time: 10 minutes.

OpenCode supports "custom providers" through the @ai-sdk/openai-compatible adapter — any server with /v1/chat/completions works, including SovereignEG.

Step 1 — Install

# Linux / macOS / WSL
curl -fsSL https://opencode.ai/install | bash
 
# or with npm (all platforms)
npm install -g opencode-ai
 
# Windows
scoop install opencode      # or: choco install opencode

Check: opencode --version

Step 2 — Put your key in the environment

export SOVEREIGNEG_API_KEY="sk-..."          # Linux / macOS
$env:SOVEREIGNEG_API_KEY = "sk-..."          # Windows PowerShell

Step 3 — Create the config

Create opencode.json in your project folder (project config — simplest, works on every OS), or put it in ~/.config/opencode/opencode.json to use it in every project (global config, Linux/macOS).

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "sovereigneg": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "SovereignEG",
      "options": {
        "baseURL": "https://backend.sovereigneg.com/v1",
        "apiKey": "{env:SOVEREIGNEG_API_KEY}"
      },
      "models": {
        "SovereignEG/Qwen3.8-27B-FP8": {
          "name": "SovereignEG/Qwen3.8-27B-FP8 (SovereignEG)",
          "limit": { "context": 131072, "output": 8192 }
        }
      }
    }
  },
  "model": "sovereigneg/SovereignEG/Qwen3.8-27B-FP8"
}

What each part means:

KeyMeaning
provider.sovereignegThe provider id you will see in /models. Any name works
npm@ai-sdk/openai-compatible = "talk OpenAI chat-completions format"
options.baseURLhttps://backend.sovereigneg.com/v1
options.apiKey{env:NAME} reads the key from an environment variable — never write the key into the file
modelsOnly the models you list appear in the picker. Use the exact ids from /v1/models
limit.contextLets OpenCode manage the context window and compaction
model (top level)Default model in the form provider/model-id

Step 4 — Run it

cd your-project
opencode

Inside OpenCode:

  • /models — check that SovereignEG is listed and pick a model (from a normal terminal, opencode models prints the same list).
  • /init — makes an AGENTS.md describing your repo (commit it).
  • Type a task: "Add input validation to the signup form and write a test."
  • /undo and /redo — roll back or restore file changes.

Step 5 — Add more SovereignEG models

Copy any id from the model list into the models block:

curl -H "Authorization: Bearer $SOVEREIGNEG_API_KEY" https://backend.sovereigneg.com/v1/models

Troubleshooting

ProblemFix
Provider missing from /modelsJSON is invalid, or the file is in the wrong folder. Run opencode from the folder that holds opencode.json
401SOVEREIGNEG_API_KEY is not set in the same terminal you launched opencode from
400 model_not_foundThe model key inside models must be the exact id from /v1/models
Tool calls fail / model just talksPick a model that supports tools (supports_tools: true in /v1/models)
Answers get cut offRaise limit.output

Next: Hermes Agent