# Use Xantly with OpenCode

[OpenCode](https://opencode.ai) (github.com/sst/opencode) is a fully OSS AI coding CLI that leans on the Vercel AI SDK. Its custom-provider config is the cleanest BYO story in the ecosystem, one JSON block and every feature works: chat, edit, agent, streaming, tool calls.

## Prerequisites

- OpenCode installed: `npm install -g @opencode-ai/cli` (or use `npx @opencode-ai/cli`)
- A Xantly API key, [create one](/dashboard/api-keys)

## Setup

Edit `~/.config/opencode/opencode.jsonc` (create it if missing):

```jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "xantly": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://api.xantly.com/v1",
        "apiKey": "xantly_sk_..."
      },
      "models": {
        "xantly/auto-quality": { "name": "Xantly Quality (BaRP T1)" },
        "xantly/auto-value":   { "name": "Xantly Value (BaRP T2)" },
        "xantly/auto-speed":   { "name": "Xantly Speed (BaRP T3)" },
        "anthropic/claude-sonnet-4.6": { "name": "Claude Sonnet 4.6 (pinned)" },
        "openai/gpt-5.4":               { "name": "GPT-5.4 (pinned)" }
      }
    }
  },
  "model": "xantly/auto-quality"
}
```

Or use the equivalent env-var style for CI:

```bash
export OPENCODE_PROVIDER_XANTLY_BASE_URL=https://api.xantly.com/v1
export OPENCODE_PROVIDER_XANTLY_API_KEY=xantly_sk_...
```

## Verify

```bash
cd any-project
opencode
# at the prompt:
> list files in this directory and tell me what this codebase does
```

OpenCode should fire `read_file` / `list_files` tool calls against Xantly, return a summary, and log the request in your dashboard with cost + cache status.

## Model choice

OpenCode's agent mode uses tools heavily, multi-file reads, multi-step plans, parallel edits. Recommended:

| Model ID | Why |
|---|---|
| `xantly/auto-quality` | BaRP picks the best T1, safest for agent mode. |
| `anthropic/claude-sonnet-4.6` | Rock-solid tool calling. |
| `openai/gpt-5.4` | Strong structured outputs. |
| `xantly/auto-value` | Budget mode for routine tasks. |

## What you get

- **Semantic cache across sessions.** OpenCode tends to re-read the same files at the start of every session. L1/L2 cache turns those into free hits after the first run.
- **Waterfall fallback.** Mid-agent provider failures don't kill the session, Xantly silently retries on the next-best model.
- **Memory across projects.** OpenCode's `@mention` context enrichment can route through Xantly's L3 graph memory for cross-project knowledge. Opt in via `X-Xantly-Memory-Mode: full`.
- **Cost per turn.** Every agent turn logs with cost + latency, so you can see exactly what the refactor cost.

## Gotchas

**`@ai-sdk/openai-compatible` version matters.** OpenCode pins this transitively. If your `opencode.jsonc` doesn't load, run `opencode --version` and verify it's on 0.14.0+.

**Streaming vs non-streaming.** OpenCode uses streaming by default. Xantly supports it natively (OpenAI SSE shape). If you see chunks arriving slowly, check your network, Xantly's p95 stream overhead is <20ms.

**Custom provider names must be valid JSON keys.** `xantly` works. Avoid hyphens or weird chars in the provider key.

## Next steps

- [Cline](/docs/use-with-cline), VS Code equivalent.
- [Aider](/docs/use-with-aider), terminal-native pair programmer, role-split for cost savings.
- [Bring Your Own Key](/docs/bring-your-own-key), route OpenCode through your own provider credits.
