Skip to main content

OpenCode

Route OpenCode through otari.ai to track usage, enforce budgets, and inspect traces for every request, without changing how you code.

How it works

Otari exposes an OpenAI-compatible endpoint at https://api.otari.ai/v1. OpenCode lets you register any OpenAI-compatible backend as a provider, so you point it at otari.ai with a workspace token and every request flows through the platform.

You keep using OpenCode exactly as before. otari.ai sits in front of your providers and records usage, applies budgets, and captures traces, with no application code changes.

1. Generate a workspace token

  1. Open your workspace and go to the API Keys tab.

  2. Under workspace tokens, click Generate.

  3. Copy the token (it starts with tk_). This is shown only once.

Keep it secret. Treat the token like a password, and pass it via an environment variable rather than committing it to your config.

2. Add your provider keys (optional)

To use your own upstream credentials, add them in the Providers tab under Provider Keys (BYOK) for the providers you want, such as OpenAI or Anthropic. Skip this if your workspace already has the keys it needs.

3. Configure OpenCode

Add otari.ai as a provider in your opencode.jsonc:

{
"provider": {
"otari": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.otari.ai/v1",
"apiKey": "{env:OTARI_API_KEY}"
}
}
}
}

Then export your workspace token so OpenCode reads it from the environment instead of the config file:

export OTARI_API_KEY=tk_your_token

4. Run OpenCode

Pick a model from the otari.ai catalog using the otari/<selector> form (the otari provider id comes from your config) and start OpenCode:

opencode --model otari/mzai:moonshotai/Kimi-K2.6

Every request now routes through otari.ai. Open your dashboard to watch usage, cost, and traces appear in real time.

Model format

After the otari/ prefix, the selector takes one of two forms:

  • Managed models (hosted by otari.ai, no provider key needed): mzai:<catalog-id>, for example otari/mzai:moonshotai/Kimi-K2.6. The managed catalog is open-weight models; browse it on the Models page.

  • Your own provider keys (BYOK, including proprietary models): <provider>/<model> with no mzai: prefix, for example otari/openai/gpt-4o or otari/anthropic/claude-sonnet-4-6.

Did this answer your question?