# OpenCode

Source: https://aiand-docs-staging.pages.dev/integrations/opencode/

[OpenCode](https://opencode.ai) is an open source AI coding agent available as a terminal interface, CLI, IDE extension, and desktop app. ai& ships as a built-in OpenCode provider: connect with your API key and ai& models appear in the model picker.

<Aside type="note">
  Use a model with the `tool_calling` capability from the [catalog](/models/catalog/) for
  coding-agent workflows. The examples below use `moonshotai/kimi-k3`.
</Aside>

## 1. Install OpenCode

For the terminal or one-shot CLI:

<Tabs syncKey="os">
<TabItem label="macOS / Linux">

```bash
curl -fsSL https://opencode.ai/install | bash
```

Other supported installers include npm and Homebrew:

```bash
npm install -g opencode-ai
brew install anomalyco/tap/opencode
```

</TabItem>
<TabItem label="Windows">

OpenCode recommends WSL for the terminal experience. You can also install the Windows package:

```powershell
choco install opencode
```

or:

```powershell
scoop install opencode
```

</TabItem>
</Tabs>

For the desktop app, download **OpenCode Desktop** from [opencode.ai/download](https://opencode.ai/download), or install it with a package manager:

<Tabs>
<TabItem label="macOS">

```bash
brew install --cask opencode-desktop
```

</TabItem>
<TabItem label="Windows">

```powershell
scoop bucket add extras
scoop install extras/opencode-desktop
```

</TabItem>
</Tabs>

## 2. Connect ai&

Create an API key in the [ai& console](https://console.aiand.com/api-keys), then add it to OpenCode in whichever surface you use.

### Terminal

In the OpenCode TUI, run:

```text
/connect
```

Choose **ai&** from the provider list and paste your `sk-...` key. OpenCode stores the credential and reuses it in future sessions.

Outside the TUI, `opencode auth login` walks through the same provider list from your shell.

### Desktop app

Open **Settings → Providers → View all providers**, search for **ai&**, and paste your `sk-...` key. The Providers screen lists only connected and popular providers by default, so ai& does not appear until you open the full list.

### Environment variable

For CI, scripts, or non-interactive runs:

<Tabs syncKey="os">
<TabItem label="macOS / Linux">

```bash
export AIAND_API_KEY="sk-your-aiand-api-key"
```

</TabItem>
<TabItem label="Windows (PowerShell)">

```powershell
$env:AIAND_API_KEY = "sk-your-aiand-api-key"
```

</TabItem>
</Tabs>

<Aside type="caution">
  Environment variables only reach the Desktop app when it is launched from a shell that already has
  `AIAND_API_KEY` exported. Double-clicking the app icon does not pick them up; add the key under
  **Settings → Providers → View all providers → ai&** instead.
</Aside>

## 3. Pick a model

Open the model picker and choose a model from the **ai&** section:

```text
/models
```

Model names use `aiand/<model-id>`, for example `aiand/moonshotai/kimi-k3`. OpenCode pulls its provider catalog automatically, so new ai& models appear after a restart without reinstalling anything.

## 4. Run OpenCode

Interactive terminal UI:

```bash
opencode
```

One-shot CLI:

```bash
opencode run "say hi in one word"
```

## Desktop App

The Desktop app uses the same built-in ai& provider as the terminal:

1. Install **OpenCode Desktop** from [opencode.ai/download](https://opencode.ai/download).
2. Open **Settings → Providers → View all providers**, search for **ai&**, and paste your API key.
3. Open a project folder.
4. Run `/models` and choose an `aiand/...` model.

## Verify

Check that OpenCode can reach ai&:

```bash
opencode run -m aiand/moonshotai/kimi-k3 "reply with only: ok"
```

You can also test the key directly against ai&:

<Tabs syncKey="os">
<TabItem label="macOS / Linux">

```bash
curl -sS https://api.aiand.com/v1/models \
  -H "Authorization: Bearer $AIAND_API_KEY"
```

</TabItem>
<TabItem label="Windows (PowerShell)">

```powershell
Invoke-RestMethod https://api.aiand.com/v1/models `
  -Headers @{ Authorization = "Bearer $env:AIAND_API_KEY" }
```

</TabItem>
</Tabs>

## Troubleshooting

- **ai& is missing from the provider list** — update OpenCode to a recent version and restart it so it refreshes the provider catalog.
- **A model from the ai& catalog is missing in `/models`** — the models.dev listing can lag behind the [ai& catalog](/models/catalog/). Restart OpenCode; if it is still missing, pass the model id directly with `opencode run -m aiand/<model-id>`.
- **Unauthorized request** — re-enter the key with `/connect` or `opencode auth login` (terminal) or under **Settings → Providers → View all providers → ai&** (Desktop), or confirm `AIAND_API_KEY` is set in the process running OpenCode.
- **The Desktop app does not see your key** — add it under **Settings → Providers → View all providers → ai&**, or launch Desktop from a shell where `AIAND_API_KEY` is already exported.
