Skip to content

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-pickle
  • opencode/deepseek-v4-flash-free
  • opencode/mimo-v2.5-free
  • opencode/nemotron-3-ultra-free
  • opencode/north-mini-code-free

OpenCode Go models

Paid subscription:

  • opencode-go/deepseek-v4-flash
  • opencode-go/deepseek-v4-pro
  • opencode-go/glm-5.1
  • opencode-go/glm-5.2
  • opencode-go/kimi-k2.6
  • opencode-go/kimi-k2.7-code
  • opencode-go/mimo-v2.5
  • opencode-go/mimo-v2.5-pro
  • opencode-go/minimax-m2.7
  • opencode-go/minimax-m3
  • opencode-go/qwen3.6-plus
  • opencode-go/qwen3.7-max
  • opencode-go/qwen3.7-plus

OpenAI-backed models

Bring-your-own-key:

  • openai/gpt-5.3-codex-spark
  • openai/gpt-5.4
  • openai/gpt-5.4-fast
  • openai/gpt-5.4-mini
  • openai/gpt-5.4-mini-fast
  • openai/gpt-5.5
  • openai/gpt-5.5-fast
  • openai/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

ErrorCauseFix
ToolNotFoundErrorOpenCode CLI is not installedInstall OpenCode
ToolAuthErrorModel backend requires authRun the auth command from startAuth()
ToolUnavailableErrorCLI found but not respondingRestart OpenCode or check your network
ProviderExecutionErrorInvalid model name or CLI errorVerify the model name and OpenCode version
TimeoutErrorRequest took too longIncrease 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

Released under the MIT License. · llms.txt