> 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/otari/for-integrators/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.

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

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/models` returns for your key, for example `otari/openai:gpt-4o`, `otari/anthropic:claude-sonnet-4-6` or `otari/mistral:mistral-large-latest`. `provider/model` works as well as `provider:model`.
* **On your own gateway:** `provider:model` for any provider it is configured with, for example `otari/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](/otari/for-integrators/use-with-claude-code.md): drive the Claude Code CLI through the same Otari via the Anthropic Messages API.
* [Use with Codex](/otari/for-integrators/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/otari/for-integrators/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.
