opencode

Use Cocobox-hosted models from the opencode terminal CLI, with the Cocobox MCP server attached.

Last updated

opencode is an open-source terminal AI coding agent. It speaks the OpenAI Chat Completions wire format and supports MCP servers. Cocobox plugs straight in — point it at our base URL and (optionally) attach the Cocobox MCP server.

Prerequisites

  • A Cocobox account with an active subscription (or an active 15-day trial).
  • An sk-coco-* API key. See API keys.
  • opencode installed locally (brew install sst/tap/opencode or see the opencode README).

Configure opencode (model only)

The simplest setup uses Cocobox just for the model.

export OPENAI_BASE_URL=https://api.cocobox.io/v1
export OPENAI_API_KEY=sk-coco-…
opencode --model sonnet

Inside opencode, ask it anything — it will route through /v1/chat/completions on Cocobox’s infrastructure. Available aliases: tambor, haiku, sonnet, opus, prisma, nova-premier, deepseek-r1. See Models for the full list.

Configure opencode (model + MCP)

To let opencode actually talk to your databases, attach the Cocobox MCP server too. Edit ~/.config/opencode/config.json (create if missing):

{
  "provider": {
    "openai": {
      "baseURL": "https://api.cocobox.io/v1",
      "apiKey": "sk-coco-…"
    }
  },
  "mcp": {
    "cocobox": {
      "type": "remote",
      "url": "https://api.cocobox.io/v1/mcp",
      "headers": {
        "Authorization": "Bearer sk-coco-…"
      }
    }
  }
}

Restart opencode. Run /mcp (or check the status bar) to confirm the cocobox server is connected and its tools are listed.

Try it

Ask:

List the tables in my “marketing” connection and tell me which ones don’t have a primary key.

opencode picks sql_list_connections, then sql_list_tables, then sql_describe for each table, and synthesizes the answer. Every tool call is recorded in your Cocobox audit log with the opencode user-agent.

Tips

  • Prefer a per-machine key. Set requestBudget low and rotate when you switch laptops.
  • Use cheap models for tool-heavy loops. haiku is excellent at MCP orchestration and costs 1 credit per call (or use tambor for the cheapest tier at 0.33 credits).
  • Pin a specific connection with a system prompt so opencode doesn’t have to discover it every session: “Use the connection named prod-readonly by default.”

Troubleshooting

  • 401 unauthorized — your OPENAI_API_KEY is missing or wrong. Verify with curl -H "Authorization: Bearer $OPENAI_API_KEY" https://api.cocobox.io/v1/models.
  • 403 tools_disabled — the key was created with toolsEnabled: false. PATCH it (Settings → API keys → toggle).
  • MCP server not appearing — check that opencode’s config file is the one it’s actually reading (opencode --config-path prints the resolved path).