Use with opencode
opencode lets you register any OpenAI-compatible backend as a provider. Otari exposes an OpenAI-compatible endpoint (POST /api/v1/chat/completions), so you can route opencode through Otari to get budgets, usage tracking, and traces without changing how you code.
Quick start
Add Otari as a provider in your opencode.jsonc:
{
"provider": {
"otari": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "http://localhost:8000/api/v1",
"apiKey": "{env:OTARI_API_KEY}"
}
}
}
}baseURL is the Otari API root, /api/v1 (opencode appends /chat/completions itself). Point it at the gateway you are actually using: http://localhost:8000/api/v1 for local development, your self-hosted gateway URL plus /api/v1, or https://api.otari.ai/api/v1 when using otari.ai. Accounts in otari.ai's EU region use https://eu.api.otari.ai/api/v1 instead: api.otari.ai answers an EU key with 421 Misdirected Request, naming the host to use.
Export your key so opencode reads it from the environment instead of the config file, then run with a model:
export OTARI_API_KEY=<your-otari-key> # from otari.ai, or from your own gateway
opencode --model otari/openai:gpt-4oThe apiKey is sent as Authorization: Bearer <key>, which Otari accepts for every key it issues.
Choosing a model
The provider id is otari (from your config) and the model selector is whatever your deployment expects:
On otari.ai: any model your organization's catalog lists, which
GET /api/v1/modelsreturns for your key, for exampleotari/openai/gpt-4oorotari/anthropic/claude-sonnet-4-6, which let Otari choose the provider. Aprovider:modelselector such asotari/anthropic:claude-sonnet-4-6pins one.On your own gateway:
provider:modelfor any provider it is configured with, for exampleotari/openai:gpt-4o.
Any model in the catalog works; Otari routes the request to the right provider and records usage and cost for it the same way as any other client.
See also
Use with Claude Code: drive the Claude Code CLI through the same Otari via the Anthropic Messages API.
Use with Codex: drive the Codex CLI through the same Otari via the OpenAI Responses API.
Last updated
Was this helpful?
