Skip to main content
OpenCode is a terminal-based coding agent that supports custom model providers. Add Tokios as a provider in opencode.json using the @ai-sdk/openai-compatible package, point options.baseURL at https://api.tokios.com/v1, and list your Tokios deployment name under models. OpenCode then routes every agent request down your private connector tunnel to your local model.

Prerequisites

  • A running Tokios connector paired with your local model — see Connector install
  • A registered model deployment name — see Register a model
  • A Tokios API key (sk-tok-…) — see API keys
  • OpenCode installed

Configure OpenCode

Add a Tokios provider block to your opencode.json config. The exact config file location (project-local opencode.json vs. a global config path) and the precise key names (options, npm, models) can vary across OpenCode releases, so confirm them against your installed version’s provider schema.
opencode.json
Replace gemma-tunnel with the public deployment name you registered on the Models tab — not the local model id your backend (Ollama, llama.cpp, vLLM, or LM Studio) uses. Replace sk-tok-YOUR_KEY with your own key, and avoid committing it into a shared or version-controlled config file.
options.baseURL must include /v1. OpenCode’s OpenAI-compatible provider sends requests relative to this URL, so a base URL without /v1 fails to reach the Tokios API surface.

Pick a tool-capable model

OpenCode’s agent relies on tool calling to read files, run commands, and edit code. Not every local model handles tool calls reliably — pick a deployment backed by a model with strong tool-calling support before you rely on OpenCode’s agent for real edits. See Choose a local model for how to compare candidates.

Troubleshooting

The API key OpenCode sent is missing, malformed, or has been revoked. Confirm options.apiKey holds the full sk-tok-… key with no extra whitespace, and check its status on the Keys tab.
The model key under models doesn’t match a registered deployment. Confirm it exactly matches the public name on the Models tab — not your Ollama, llama.cpp, vLLM, or LM Studio local model id.
The connector for that deployment is offline or at its concurrency cap. Check the Connectors tab — the connector needs to show as Online, and the machine running it needs to still be up and reachable.

Next steps

Compatible clients

See base URL and key setup for other OpenAI- and Anthropic-compatible clients.

Choose a local model

Compare backends and models before you commit a deployment to agentic workflows.