OpenCode
OpenCode is a CLI-based AI coding tool that supports free hosted models, paid OpenCode Go models, and OpenAI-backed models. switchboard-ai-sdk discovers the local CLI and normalizes chat, health checks, auth, and model listing.
How discovery works
ts
import { discover } from "switchboard-ai-sdk";
const tools = await discover();
const opencode = tools.find((t) => t.id === "opencode");
console.log({
available: opencode?.available,
models: opencode?.models,
defaultModel: opencode?.defaultModel,
});OpenCode can enumerate its available models through the CLI, so models is populated when discovery succeeds.
How auth works
OpenCode may require authentication depending on the model backend.
ts
const tool = await connect("opencode");
const auth = await tool.checkAuth();
if (auth.authStatus === "unauthenticated") {
const result = await tool.startAuth();
console.log("Run:", result.command);
console.log("Instructions:", result.instructions);
}How model selection works
OpenCode model names use the format provider/model-name. You can set a default:
ts
import { configure } from "switchboard-ai-sdk";
configure({
opencodeModel: "opencode/deepseek-v4-flash-free"
});Free models
No subscription required:
opencode/big-pickleopencode/deepseek-v4-flash-freeopencode/mimo-v2.5-freeopencode/nemotron-3-ultra-freeopencode/north-mini-code-free
OpenCode Go models
Paid subscription:
opencode-go/deepseek-v4-flashopencode-go/deepseek-v4-proopencode-go/glm-5.1opencode-go/glm-5.2opencode-go/kimi-k2.6opencode-go/kimi-k2.7-codeopencode-go/mimo-v2.5opencode-go/mimo-v2.5-proopencode-go/minimax-m2.7opencode-go/minimax-m3opencode-go/qwen3.6-plusopencode-go/qwen3.7-maxopencode-go/qwen3.7-plus
OpenAI-backed models
Bring-your-own-key:
openai/gpt-5.3-codex-sparkopenai/gpt-5.4openai/gpt-5.4-fastopenai/gpt-5.4-miniopenai/gpt-5.4-mini-fastopenai/gpt-5.5openai/gpt-5.5-fastopenai/gpt-5.5-pro
Minimal example
ts
import { configure, connect } from "switchboard-ai-sdk";
configure({
opencodeModel: "opencode/deepseek-v4-flash-free"
});
const tool = await connect("opencode");
const auth = await tool.checkAuth();
if (auth.authStatus === "unauthenticated") {
const start = await tool.startAuth();
console.log(start.instructions);
process.exit(0);
}
const result = await tool.chat({
messages: [
{ role: "user", content: "Write a Python function that reverses a string." }
],
});
console.log(result.message.content);Common errors
| Error | Cause | Fix |
|---|---|---|
ToolNotFoundError | OpenCode CLI is not installed | Install OpenCode |
ToolAuthError | Model backend requires auth | Run the auth command from startAuth() |
ToolUnavailableError | CLI found but not responding | Restart OpenCode or check your network |
ProviderExecutionError | Invalid model name or CLI error | Verify the model name and OpenCode version |
TimeoutError | Request took too long | Increase timeoutMs |
Limitations
- Free models may change; verify current availability in OpenCode docs
- Some models route to cloud providers, so "local tool" does not always mean "offline"
- OpenCode is an agent tool and may modify files
- Model lineup changes frequently; check OpenCode models for the latest list