Configure OpenCode with DeepSeek, Kimi K3, and GLM-5.3
You can run OpenCode on Inference.net in under two minutes with one copy-paste opencode.json file or one CLI command (fast opencode on). Wiring deepseek-v4.1-flash-1017, moonshotai/kimi-k3, moonshotai/kimi-k3.1-pro, and glm-5.3 under one provider gives OpenCode 1M-token context windows, full tool calling, reasoning effort toggles (Ctrl+T), and per-agent switching between a $0.0329/session build loop and frontier open-weight planning models.
Step 1: Create and export your Inference.net API key
Create a free account at /register, generate a project key in API keys, and export it in your shell profile (~/.zshrc or ~/.bashrc) before launching OpenCode:
export INFERENCE_API_KEY="inf_sk_..."OpenCode resolves {env:INFERENCE_API_KEY} at startup, so restart OpenCode after adding or rotating the key.
Step 2: Copy-paste opencode.json
Save this configuration to ~/.config/opencode/opencode.json (global) or ./opencode.json (repository-scoped). Every model ID, context window, max output ceiling, modality list, and reasoning variant below matches live GET https://api.inference.net/v1/models (verified 2026-12-06):
{
"$schema": "https://opencode.ai/config.json",
"model": "inference/deepseek-v4.1-flash-1017",
"small_model": "inference/deepseek-v4.1-flash-1017",
"provider": {
"inference": {
"name": "Inference.net",
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.inference.net/v1",
"apiKey": "{env:INFERENCE_API_KEY}",
"headers": {
"x-inference-task-id": "opencode"
}
},
"models": {
"deepseek-v4.1-flash-1017": {
"name": "DeepSeek V4.1 Flash 1017",
"attachment": true,
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"limit": { "context": 1040000, "output": 393216 },
"tool_call": true,
"reasoning": true,
"variants": {
"none": { "reasoning_effort": "none" },
"low": { "reasoning_effort": "low" },
"high": { "reasoning_effort": "high" },
"max": { "reasoning_effort": "max" }
}
},
"glm-5.3": {
"name": "GLM 5.3",
"attachment": false,
"modalities": {
"input": ["text"],
"output": ["text"]
},
"limit": { "context": 1048576, "output": 943718 },
"tool_call": true,
"reasoning": true,
"variants": {
"low": { "reasoning_effort": "low" },
"high": { "reasoning_effort": "high" },
"max": { "reasoning_effort": "max" }
}
},
"moonshotai/kimi-k3": {
"name": "Kimi K3",
"attachment": true,
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"limit": { "context": 1048576, "output": 1048576 },
"tool_call": true,
"reasoning": true,
"variants": {
"none": { "reasoning_effort": "none" },
"low": { "reasoning_effort": "low" },
"high": { "reasoning_effort": "high" },
"max": { "reasoning_effort": "max" }
}
},
"moonshotai/kimi-k3.1-pro": {
"name": "Kimi K3.1 Pro",
"attachment": true,
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"limit": { "context": 1048576, "output": 1048576 },
"tool_call": true,
"reasoning": true,
"variants": {
"none": { "reasoning_effort": "none" },
"low": { "reasoning_effort": "low" },
"high": { "reasoning_effort": "high" },
"max": { "reasoning_effort": "max" }
}
}
}
}
}
}Three config details prevent the most common OpenCode errors:
- Keep the key name
"inference"under"provider": Overriding the built-ininferenceentry ensures OpenCode callshttps://api.inference.net/v1instead of an outdatedmodels.devbase URL (https://inference.net/v1), while keeping"provider"(singular) compatible with both OpenCode 1.x and 2.x. - Keep the
moonshotai/prefix on Kimi IDs: Usemoonshotai/kimi-k3andmoonshotai/kimi-k3.1-proso requests hit Inference.net-hosted US infrastructure with default ZDR and live serverless rates. - Optional US-only endpoint: All four models above run on US servers, so you can change
baseURLtohttps://us.api.inference.net/v1for US-only routing.
Alternative: one-command setup with split build and plan models
If you prefer automatic setup with a backup of your existing config, use the fast CLI to assign separate models to OpenCode's build and plan agents:
npm install -g @inference/fast
fast login
# Use DeepSeek V4.1 Flash for fast build loops and Kimi K3.1 Pro for planning
fast opencode on \
--build deepseek-v4.1-flash-1017 \
--plan moonshotai/kimi-k3.1-proFor native Anthropic /v1/messages (@ai-sdk/anthropic) config and Inference Pass (inf pass on opencode) instructions, see the full OpenCode integration documentation.
Real OpenCode session cost math
Coding agents replay repository files, tool schemas, and prior turns on every step. The table below uses our standard Coding Agent workload preset: 40 turns per session, 14,000 average input tokens per turn (560K total input = 84K fresh + 476K cached reads at 85% prompt caching), and 900 average output tokens per turn (36K total output).
All rates below were verified from GET https://api.inference.net/v1/models on 2026-12-06:
| OpenCode setup | Fresh / Cached / Output ($/1M) | 40-turn session cost | Monthly (100 sessions/dev) | Best workflow role |
|---|---|---|---|---|
deepseek-v4.1-flash-1017 (all turns) | $0.08 / $0.007 / $0.635 | $0.0329 | $3.29 | Default build, small_model, test fixes |
Hybrid: 30 deepseek-v4.1-flash-1017 + 10 glm-5.3 | Tiered build + plan | $0.0628 | $6.28 | Low-cost build loops + deep refactor planning |
glm-5.3 (all turns) | $0.084 / $0.079 / $3.00 | $0.1527 | $15.27 | Single-model long-output refactors |
Hybrid: 30 deepseek-v4.1-flash-1017 + 10 moonshotai/kimi-k3.1-pro | Tiered build + plan | $0.1670 | $16.70 | Fast build execution + frontier K3.1 Pro planning |
moonshotai/kimi-k3.1-pro (all turns) | $1.80 / $0.198 / $9.00 | $0.5694 | $56.94 | Complex multi-file architecture end to end |
moonshotai/kimi-k3 (all turns) | $0.245 / $0.224 / $15.00 | $0.6672 | $66.72 | Input-heavy repo exploration and synthesis |
claude-sonnet-4-6 (reference) | $3.00 / $0.30 / $15.00 | $0.9348 | $93.48 | Proprietary baseline comparison |
Splitting 30 build turns onto deepseek-v4.1-flash-1017 ($0.0247) and 10 plan turns onto moonshotai/kimi-k3.1-pro ($0.1424) totals $0.1670 per 40-turn session: 3.4x cheaper than running moonshotai/kimi-k3.1-pro on every turn ($0.5694) and 5.6x cheaper than claude-sonnet-4-6 ($0.9348).
Plug your team's session count and cache hit rate into the LLM Pricing Calculator or Prompt Cache Calculator.
Switching models, reasoning effort, and caching inside OpenCode
- Switch models mid-session: Open OpenCode's model picker with
/models(orCtrl+XthenM). All four configured models appear under Inference.net. - Tune reasoning effort on the fly: Press
Ctrl+Tto cycle variants (none,low,high,maxon DeepSeek V4.1 Flash and Kimi K3/K3.1;low,high,maxon GLM-5.3). Dropping DeepSeek V4.1 Flash tolowornonespeeds up repetitive edits and cuts output tokens. - Prompt caching behavior by model:
deepseek-v4.1-flash-1017,moonshotai/kimi-k3, andmoonshotai/kimi-k3.1-prouse automatic prefix caching with no cache-key header needed (never sendprompt_cache_keyto DeepSeek V4.1 Flash).glm-5.3uses a stableprompt_cache_keywhen called directly via API for cache affinity. Confirm cache hits in Usage.
Zero Data Retention (ZDR) and US residency scope
All four models in the opencode.json above (deepseek-v4.1-flash-1017, glm-5.3, moonshotai/kimi-k3, and moonshotai/kimi-k3.1-pro) are Inference.net-hosted US serverless routes. They are eligible for default Zero Data Retention under SOC 2 Type II controls (prompts and completions are not stored after processing or used for training) and accept US-pinned requests via https://us.api.inference.net/v1. If you add externally routed catalog models (such as deepseek-v4-pro, kimi-k2.6, or glm-5.2) to opencode.json, those external routes are excluded from Inference.net's ZDR policy and follow their upstream provider's retention terms.
Frequently asked questions
Why did OpenCode fail with a 301 or 404 error using the built-in inference provider?
OpenCode's bundled models.dev catalog can point to https://inference.net/v1 instead of https://api.inference.net/v1. Copy the opencode.json block above so "baseURL": "https://api.inference.net/v1" overrides the built-in URL.
Should I use @ai-sdk/openai-compatible or @ai-sdk/anthropic in OpenCode?
Start with @ai-sdk/openai-compatible (https://api.inference.net/v1) because it exposes reasoning_effort variants cleanly across DeepSeek, Kimi, and GLM models. Use @ai-sdk/anthropic (also with baseURL: "https://api.inference.net/v1", since @ai-sdk/anthropic appends /messages) if you specifically want Anthropic Messages wire formatting.
Which model is best for OpenCode's small_model slot?
Set "small_model": "inference/deepseek-v4.1-flash-1017". At $0.08 fresh input, $0.007 cached reads, and $0.635 output per 1M tokens with 1.04M context, it handles title generation, compaction, and quick repo lookups for fractions of a cent.
Can I route OpenCode through a team LiteLLM Proxy instead of individual keys?
Yes. Run a centralized LiteLLM Proxy backed by Inference.net and point OpenCode's baseURL to http://127.0.0.1:4000/v1 (or your internal proxy HTTPS URL) with your LiteLLM virtual key.
Related OpenCode and model resources
- Integration docs: OpenCode Integration Docs · Claude Code Integration · LiteLLM Proxy & SDK · Integrations Hub
- Model family hubs: DeepSeek API · Kimi API · GLM API
- Pricing guides & tools: DeepSeek API Pricing · Kimi K3 Pricing · GLM-5 Pricing · LLM Pricing Calculator
Connect OpenCode to DeepSeek, Kimi K3, and GLM-5.3
Create a free Inference.net API key to run 1M-context open-weight models in OpenCode with automatic prompt caching, 0% markup billing, and hosted US Zero Data Retention.
Create API key