> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pangolin.net/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenCode

> Connect OpenCode to a Pangolin AI Gateway resource

OpenCode configures each model provider separately, so it can talk to whichever API formats your resource supports — Anthropic Messages, OpenAI Chat/Responses, or both, depending on which providers are attached. See [AI Gateway Overview](/manage/ai/overview) if you haven't set that up yet.

You'll need the resource's URL (its `<endpoint>`) and its API key (`<key>`). Both are on the resource's Keys page.

<Note>
  **Public vs. private resources**

  Wherever these instructions show `<key>`, what you put there depends on the resource type:

  * **Public resource** - reachable from anywhere, so the gateway checks a [virtual API key](/manage/ai/virtual-api-keys). Copy it from the resource URL after login, the Resource Launcher more-info panel, or `https://app.pangolin.net/<org-id>/keys` (use your self-hosted dashboard URL in place of `app.pangolin.net` if you self-host).
  * **Private resource** - only reachable from devices connected to your Pangolin network, so no key is checked. You must have the [Pangolin client](/manage/clients/install-client) installed and connected. Use the literal string `none` as the key.

  Don't delete the key field for private resources. Most clients refuse to start without *some* key set, so they need an inert placeholder rather than a missing one.
</Note>

## Fastest: Pangolin CLI

[Install the Pangolin CLI](/manage/clients/install-client#quick-install-recommended) if you don't have it, then log in:

```bash theme={"theme":"gruvbox-light-hard"}
pangolin login
```

Configure OpenCode against a resource:

```bash theme={"theme":"gruvbox-light-hard"}
pangolin configure opencode
```

This prompts you to pick an organization and resource (if you have more than one), then asks which OpenCode provider ID(s) should point at this gateway — defaults to `anthropic,openai`, but you can enter any comma-separated list OpenCode recognizes (e.g. `openrouter,google`). It fetches a key for you if needed and writes `opencode.json` and `auth.json`. To skip the org/resource prompts:

```bash theme={"theme":"gruvbox-light-hard"}
pangolin configure opencode --resource <resource-niceid-or-domain>
```

To undo it:

```bash theme={"theme":"gruvbox-light-hard"}
pangolin configure opencode --reset
```

## Manual setup

Merge this into your global `opencode.json` (`~/.config/opencode/opencode.json`, or `$XDG_CONFIG_HOME/opencode/opencode.json` if set):

```json theme={"theme":"gruvbox-light-hard"}
{
    "$schema": "https://opencode.ai/config.json",
    "provider": {
        "anthropic": {
            "options": {
                "baseURL": "<endpoint>/v1"
            }
        },
        "openai": {
            "options": {
                "baseURL": "<endpoint>/v1"
            }
        }
    }
}
```

Then merge your key into `auth.json` (`~/.local/share/opencode/auth.json`, or `$XDG_DATA_HOME/opencode/auth.json` if set):

```json theme={"theme":"gruvbox-light-hard"}
{
    "anthropic": {
        "type": "api",
        "key": "<key>"
    },
    "openai": {
        "type": "api",
        "key": "<key>"
    }
}
```

<Warning>
  `auth.json` is required even for a private resource. OpenCode refuses to start a provider with no key at all and fails with `OpenAI API key is missing. Pass it using the 'apiKey' parameter or the OPENAI_API_KEY environment variable.` Set the key to `none` rather than leaving the entry out.
</Warning>

Only add entries for the providers your resource actually supports. To point a different OpenCode provider (`openrouter`, `google`, `groq`, etc.) at this gateway, add a matching block under `provider` in `opencode.json` and a matching key in `auth.json`.
