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

# OpenCode

> Use Edgee with OpenCode for building AI applications directly in your terminal.

Edgee's OpenAI-compatible API works with OpenCode, letting you use OpenCode's CLI agent while routing every request through Edgee for compression and observability.

## Edgee CLI setup (recommended)

The fastest way to connect OpenCode to Edgee is the CLI. It authenticates, merges an Edgee provider into your OpenCode config (populated from the live Edgee model catalog), and starts OpenCode, no config file to edit by hand.

<Steps>
  <Step title="Install the Edgee CLI">
    <Tabs>
      <Tab title="macOS / Linux">
        ```bash theme={"dark"}
        curl -fsSL https://edgee.ai/install.sh | bash

        # Accept the alias prompt (recommended).
        # If skipped: edgee alias
        # Reopen your terminal afterward.
        ```
      </Tab>

      <Tab title="Homebrew (macOS)">
        ```bash theme={"dark"}
        brew install edgee-ai/tap/edgee

        # Enable aliases (recommended).
        edgee alias
        # Reopen your terminal afterward.
        ```
      </Tab>

      <Tab title="Windows (PowerShell)">
        ```powershell theme={"dark"}
        irm https://edgee.ai/install.ps1 | iex

        # Enable aliases (recommended).
        edgee alias
        # Reopen your terminal afterward.
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Launch OpenCode through Edgee">
    Choose how you want to launch. Both options route requests through Edgee.

    <Tabs>
      <Tab title="With aliases (recommended)">
        With aliases installed in the previous step, use your usual command:

        ```bash theme={"dark"}
        opencode
        ```

        The alias runs `edgee launch` for you, so requests go through Edgee.
      </Tab>

      <Tab title="Without aliases">
        Launch explicitly through Edgee each time:

        ```bash theme={"dark"}
        edgee launch opencode
        ```

        No alias setup is required.
      </Tab>
    </Tabs>

    If you are not signed in, Edgee starts sign-in automatically at launch. Follow the prompts and select your organization when asked.

    The CLI authenticates, adds the `edgee` provider, and starts OpenCode. Token compression is enabled automatically. Pick an Edgee model from OpenCode's model picker.
  </Step>
</Steps>

After the session ends, the CLI prints a link to view token usage, compression savings, and cost breakdown in the Edgee Console.

<Accordion title="Model context windows and pricing">
  Each model the CLI writes into the `edgee` provider carries its context window and its per-million-token rates, read from the Edgee model catalog:

  ```json theme={"dark"}
  {
    "models": {
      "anthropic/claude-sonnet-4-5": {
        "name": "anthropic/claude-sonnet-4-5",
        "limit": { "context": 1000000, "output": 32000 },
        "cost": { "input": 3, "output": 15, "cache_read": 0.3, "cache_write": 3.75 }
      }
    }
  }
  ```

  Those are Claude Sonnet 4.5's catalog values: a 1M context window, $3 and $15 per million input and output tokens, $0.30 per million cached-read tokens, $3.75 per million cache-write tokens.

  Why it matters: OpenCode defaults both to `0` for a config-defined model. Without `limit`, its context gauge and auto-compaction have nothing to measure against; without `cost`, every session reports as free.

  Details on what the CLI emits:

  * `limit.context` comes from the catalog. When a model is served by several LLM providers with different windows, the value is the author's own provider entry, or the smallest declared window when the author doesn't serve it — overstating the window makes the agent compact too late and the request gets rejected.
  * `limit.output` is always `32000`. OpenCode clamps every request's `max_tokens` to its own 32k ceiling anyway, and its schema requires `output` whenever `limit` is set.
  * `cost` is in US dollars per million tokens, the same unit as OpenCode's own catalog. A model that is genuinely free gets zeroed rates rather than an omitted `cost`.
  * Tiered long-context pricing is not emitted. The catalog carries a premium above 200k tokens for a few models (Claude Sonnet 4.5 goes to $6 / $22.50 there), and OpenCode's config schema has a `cost.context_over_200k` slot, but its config merge drops that field — it survives only on the models.dev path. Declaring it would imply a tier that never takes effect.
  * Models the catalog has no entry for keep working; they just ship without `limit` or `cost`. The fetch is best-effort — if it fails, launch continues with no declared metadata.
</Accordion>

## Manual setup (advanced)

### Get your coding-agent key

Manual setup uses the key of your enrolled **OpenCode** agent, **not a standard API key** created for LLM Router applications.

1. Open the [Edgee Console](https://www.edgee.ai) and select your organization.
2. In the header, click **Set up coding agent** or **+**, select **OpenCode**, and click **Enroll**. If your agent is already enrolled, use its existing icon.
3. Click the agent's icon, then **Advanced settings → Advanced**.
4. Under **Edgee API key (for manual setup)**, click **Reveal key**, then the copy icon.

Use this key wherever the configuration below shows `<YOUR_CODING_AGENT_KEY>`.

### Configure OpenCode

Prefer to configure OpenCode yourself? Open or create `~/.config/opencode/opencode.json` and add the following configuration:

```json theme={"dark"}
{
  "$schema": "https://opencode.ai/config.json",
  // Theme configuration
  "theme": "opencode",
  "autoupdate": true,
  "provider": {
    "edgee": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "edgee",
      "options": {
        "baseURL": "https://edgee.io/v1",
        "apiKey": "<YOUR_CODING_AGENT_KEY>"
      },
      "models": {
        "anthropic/claude-sonnet-4-5": {
          "name": "claude sonnet 4.5 (edgee)",
          "limit": { "context": 1000000, "output": 32000 },
          "cost": { "input": 3, "output": 15, "cache_read": 0.3, "cache_write": 3.75 }
        },
        "openai/gpt-5.2": {
          "name": "gpt-5.2 (edgee)",
          "limit": { "context": 400000, "output": 32000 },
          "cost": { "input": 1.75, "output": 14, "cache_read": 0.175, "cache_write": 0 }
        }
      }
    }
  }
}
```

Make sure to replace `"<YOUR_CODING_AGENT_KEY>"` with the coding-agent key copied above.

Model ids use the `provider/model` form the Edgee catalog exposes. `limit` and `cost` are optional, but a model without them gets no context gauge, no auto-compaction, and a `$0` cost readout — the same reason `edgee launch opencode` declares them for you. Keep `limit.output` at `32000`: OpenCode clamps `max_tokens` to that ceiling regardless.

## Usage

Once configured, you can select the configured models directly within the OpenCode CLI interface.

When you launch OpenCode, you will be able to choose from the models you defined in the `models` section of your configuration (e.g., "mistral small (edgee)", "gpt-4 (edgee)", etc.).

## Authentication

Edgee uses standard Bearer token authentication. Your API key configured in `opencode.json` is automatically used to authenticate requests to the Edgee API.

<Note>
  Token compression is only available when routing through Edgee. You can use your own provider keys via [BYOK](/docs/features/byok) — compression still applies as long as requests go through Edgee.
</Note>

## Next Steps

* Explore [OpenCode's documentation](https://opencode.ai) for more features
* Set up [observability](/docs/features/observability) to monitor your OpenCode sessions

## Verify the connection

Send one request from the configured client, then open **Logs** in the same Edgee organization. Check the served model, provider, and key. For a CLI-launched coding agent, also inspect its session report.

If the request is missing, check that you launched through Edgee or saved the client’s gateway URL and coding-agent key. If it appears with an error, inspect the error before changing settings. See [Troubleshooting](/docs/troubleshooting) and [Gateway errors](/docs/llm-router/api-reference/errors).
