OpenCode
Connect OpenCode to Mixen — pay from your balance in roubles, a terminal coding agent with a catalog of 105+ models.
Installation
Section titled “Installation”npm install -g opencode-aiOr with Homebrew (macOS/Linux):
brew install anomalyco/tap/opencodeConfiguration
Section titled “Configuration”Create opencode.json in your project root (or globally at ~/.config/opencode/opencode.json):
{ "$schema": "https://opencode.ai/config.json", "provider": { "mixen": { "npm": "@ai-sdk/openai-compatible", "name": "Mixen AI", "options": { "baseURL": "https://api.mixen.ai/v1", "apiKey": "{env:MIXEN_API_KEY}" }, "models": { "gpt-5.6-sol": { "name": "GPT-5.6 Sol", "id": "openai/gpt-5.6-sol" }, "claude-opus-5": { "name": "Claude Opus 5", "id": "anthropic/claude-opus-5" }, "glm-5.3": { "name": "GLM 5.3", "id": "z-ai/glm-5.3" }, "glm-5.3-flash": { "name": "GLM 5.3 Flash", "id": "z-ai/glm-5.3-flash", "tool_call": true } } } }, "model": "mixen/gpt-5.6-sol"}Key points:
npm: "@ai-sdk/openai-compatible"— the driver for the/v1/chat/completionsprotocol that Mixen speaks.- The key in
modelsis a short name for OpenCode’s picker, while theidproperty is the identifier actually sent to the API. Mixen IDs contain a slash (openai/gpt-5.6-sol), so it goes intoid, and themodelfield references the key:mixen/gpt-5.6-sol. - A model’s entry in
modelsaccepts extra properties:"tool_call": true— tool-calling support (important for agent work),"reasoning": true— a reasoning-capable model; the allowed property names are listed in theconfig.jsonschema. {env:MIXEN_API_KEY}pulls the key from an environment variable, keeping it out of the git-tracked config. Alternatively run/connect→ Other → IDmixen→ paste the key: it is stored in a local auth file and picked up by matching the provider ID.
The API key environment variable (mxn-… keys are issued in the dashboard):
export MIXEN_API_KEY="your-api-key" # add to ~/.bashrc or ~/.zshrc to persistRunning
Section titled “Running”opencodeThe default model comes from the model field; switch it any time inside the session with the /models command.
Modes and agents
Section titled “Modes and agents”OpenCode has two work modes, toggled with the Tab key (the indicator sits in the lower-right corner):
- Build — the main mode: the agent edits files and runs commands;
- Plan — the agent only analyzes and proposes a change plan, without touching the project. Handy for running a complex task through Plan first, then repeating it in Build.
For routine jobs there are subagents — invoked by the primary agent or manually via @: @general for multi-step research, @explore for a fast read-only sweep of the codebase, @scout for read-only research of external docs and dependencies. Custom roles are added as files under .opencode/agents/ (project) or ~/.config/opencode/agents/ (global) — the filename becomes the agent name. Example .opencode/agents/review.md:
---description: Review changes before a commitmodel: mixen/glm-5.3-flashmode: subagentpermission: edit: deny bash: ask---
You are a strict reviewer. Check the changes for: leaked secrets,broken error handling, non-obvious names. Answer with a list offindings with file and line; if there are none, say so.model: mixen/glm-5.3-flash— each agent can have its own model; subagents inherit the calling agent’s model by default.permissionallows or denies tools (edit,bash,webfetchand others; levelsallow/ask/deny, with glob patterns like"git push": "ask").- The file body below the frontmatter is the agent’s system prompt.
Useful session commands
Section titled “Useful session commands”| Command | What it does |
|---|---|
/models |
Switch the model inside the session |
/connect |
Store a provider key in the local auth file |
/init |
Create an AGENTS.md in the project root — rules for the agent |
/undo, /redo |
Revert and re-apply the agent’s changes |
/share |
A link to the current conversation (conversations aren’t shared by default) |
Typing @ opens a fuzzy search over the project’s files — and an image can be dragged into the terminal to add it to the context.
Cache and savings for agent sessions
Section titled “Cache and savings for agent sessions”An agent session is dozens of turns sharing the same growing prefix: the rules, the files read, the edit history. That prefix fits the prompt cache perfectly:
- repeated context within 5 minutes is billed at ~10% of the input price (for claude-sonnet-5 — 21.4 ₽ per 1M instead of 213.9 ₽, for glm-5.3-flash — 1.7 ₽), and every hit extends the window by another 5 minutes — a dense session stays cached from start to finish;
- a pause longer than 5 minutes resets the cache: the next turn pays the full input price, then the discount accumulates again;
- don’t edit
AGENTS.mdand rules mid-session — a prefix change resets the cache.
A typical role layout:
| Role | Model | Price per 1M tokens |
|---|---|---|
| Primary agent: edits, hard tasks | anthropic/claude-sonnet-5 |
213.9 / 1069.5 ₽ |
| Subagents: review, search, doc research | z-ai/glm-5.3-flash |
8.4 ₽ input / 27.9 ₽ output |
This way the subagent routine runs on a cheap model while a flagship makes the decisions. When calling the API directly, reasoning depth is regulated by reasoning_effort (from off to max; a model’s levels are in GET /v1/models → capabilities.reasoning_efforts), and remember that reasoning spends the answer budget.
Recommended models
Section titled “Recommended models”| Model | ID |
|---|---|
| GPT-5.6 Sol | openai/gpt-5.6-sol |
| Claude Opus 5 | anthropic/claude-opus-5 |
| GLM 5.3 | z-ai/glm-5.3 |
| DeepSeek V4 Pro | deepseek/deepseek-v4-pro |
| Kimi K3 | moonshotai/kimi-k3 |
Full list — in the catalog. Add the models you need to the models section of the config as shown above.
Troubleshooting
Section titled “Troubleshooting”- 401 / Invalid API Key —
MIXEN_API_KEYis not set in the session where OpenCode runs (check withecho $MIXEN_API_KEY), or the key was copied incompletely. - Model not found — the
modelfield is built asmixen/<key from models>; the key is the short slash-free name, the slash stays insideid. - Requests go to another provider — the selected model is not from
mixen/*: switch it with/modelsor set themodelfield in the config. - The agent doesn’t call tools — file and command support depends on tool calling in the specific model; try another one from the catalog and give it
"tool_call": truein the config. - Plan mode makes no edits — that’s expected: Plan only proposes changes; switch to Build with the Tab key to apply them.