> For the complete documentation index, see [llms.txt](https://docs.otari.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.otari.ai/guides/agents-and-frameworks/use-with-opencode.md).

# Use with opencode

[opencode](https://opencode.ai) 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`:

```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:

```bash
export OTARI_API_KEY=<your-otari-key>      # from otari.ai, or from your own gateway
opencode --model otari/openai:gpt-4o
```

The `apiKey` is sent as `Authorization: Bearer <key>`, which Otari accepts for every key it issues.

## Choosing a model

opencode names a model as `<provider id>/<model>`, and the provider id here is `otari`, from your config. Everything after `otari/` is sent to Otari unchanged, so write it as Otari spells it. On otari.ai, `otari/openai/gpt-4o` or `otari/anthropic/claude-sonnet-4-6` lets Otari choose the provider, and a `provider:model` selector such as `otari/anthropic:claude-sonnet-4-6` pins one. On your own gateway, use `provider:model` for any provider it is configured with, such as `otari/openai:gpt-4o`. [Model format](https://docs.otari.ai/reference/gateway/models#model-format) has the spellings Otari accepts, and [Listing available models](https://docs.otari.ai/reference/gateway/models#listing-available-models) shows which models your key can use.

## See also

* [Use with Claude Code](/guides/agents-and-frameworks/use-with-claude-code.md): drive the Claude Code CLI through the same Otari via the Anthropic Messages API.
* [Use with Codex](/guides/agents-and-frameworks/use-with-codex.md): drive the Codex CLI through the same Otari via the OpenAI Responses API.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.otari.ai/guides/agents-and-frameworks/use-with-opencode.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
