> ## 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
        ```
      </Tab>

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

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

  <Step title="Launch OpenCode through Edgee">
    ```bash theme={"dark"}
    edgee launch opencode
    ```

    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.

## Manual setup (advanced)

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": "sk-edgee-..."
      },
      "models": {
        "mistral-small": {
          "name": "mistral small (edgee)"
        },
        "gpt-4": {
          "name": "gpt-4 (edgee)"
        },
        "claude-3-haiku": {
          "name": "claude 3 haiku (edgee)"
        }
      }
    }
  }
}
```

Make sure to replace `"sk-edgee-..."` with your actual Edgee API key.

## 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>

## Benefits of Using OpenCode with Edgee

<CardGroup cols={2}>
  <Card title="Unified Infrastructure" icon="server">
    Access all LLM providers through Edgee while using OpenCode's developer-friendly CLI.
  </Card>

  <Card title="Cost Control" icon="dollar-sign">
    Leverage Edgee's cost tracking and routing while building applications with OpenCode.
  </Card>

  <Card title="Reliability" icon="shield-check">
    Combine OpenCode's agent capabilities with Edgee's automatic failover and load balancing.
  </Card>

  <Card title="Observability" icon="chart-line">
    Monitor your OpenCode sessions with Edgee's built-in observability features.
  </Card>
</CardGroup>

## Next Steps

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