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

# OpenCode

> Set up OpenCode with one Concentrate API key and choose from the current model catalog.

<Info>
  OpenCode connects to Concentrate through its OpenAI-compatible provider. Model capabilities vary, so choose a model that supports the tools and inputs your workflow needs.
</Info>

<Accordion title="Reasons to Use Concentrate with OpenCode">
  1. **One API key** — Use one Concentrate key instead of managing separate provider accounts in OpenCode.
  2. **More model choice** — Select from the models available in your Concentrate catalog.
  3. **Switch models in a session** — Open `/models` to choose another `concentrate/` model.
  4. **Spend controls** — Manage usage with Concentrate keys and budgets.
  5. **Usage analytics** — Review requests, models, tokens, and costs in your [dashboard](https://concentrate.ai/dashboard).
</Accordion>

## Quick Start

<Accordion title="View prerequisites (before you begin)">
  <Steps>
    <Step title="Create a Concentrate API key">
      Create a key at [concentrate.ai/api-keys](https://concentrate.ai/api-keys). Make sure the account has credits available.
    </Step>

    <Step title="Install OpenCode">
      Follow the [official installation guide](https://opencode.ai/docs/). Verify the CLI is available:

      ```bash theme={null}
      opencode --version
      ```
    </Step>
  </Steps>
</Accordion>

Run the setup command for your system:

<Tabs>
  <Tab title="macOS / Linux / WSL">
    ```bash theme={null}
    curl -fsSL https://concentrate.ai/scripts/setup-opencode.sh | bash
    ```

    This requires `curl` and `python3`.
  </Tab>

  <Tab title="Windows PowerShell">
    ```powershell theme={null}
    irm https://concentrate.ai/scripts/setup-opencode.ps1 | iex
    ```

    This supports Windows PowerShell 5.1 and PowerShell 7. If your existing files contain timestamp strings that an older version cannot preserve, the script stops and asks you to use PowerShell 7.5 or newer.
  </Tab>
</Tabs>

The installer prompts for your API key, or offers to use an existing `CONCENTRATE_API_KEY`. It asks whether to make Concentrate your default provider. Choose **No** to keep your current default.

### Verify Installation

After the setup script finishes:

1. Run `opencode models` in a terminal and look for `concentrate/` models.
2. Launch `opencode` and open `/models`.
3. Select a `concentrate/` model and send a short prompt. A successful reply confirms the connection.

Re-run the setup script whenever you want to refresh the models available in OpenCode.

## Manual Setup

If you prefer to configure OpenCode yourself or the automated script does not work in your environment:

<Steps>
  <Step title="Add the Concentrate provider">
    Add this provider to `~/.config/opencode/opencode.json` or your existing global OpenCode config:

    ```json theme={null}
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "concentrate": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "Concentrate",
          "env": ["CONCENTRATE_API_KEY"],
          "options": { "baseURL": "https://api.concentrate.ai/v1" },
          "models": {
            "<model-id>": { "name": "<model-name>" }
          }
        }
      }
    }
    ```

    Replace the placeholders with a current [model ID and name](https://concentrate.ai/models). Keep any unrelated settings already in your config.

    <Note>
      This example uses OpenCode v1 config syntax, which [OpenCode v2 still accepts](https://opencode.ai/v2/docs/migrate-v1#use-your-existing-configuration). For native v2 syntax, see OpenCode's [custom provider guide](https://opencode.ai/v2/docs/providers#custom).
    </Note>
  </Step>

  <Step title="Provide your API key">
    Set `CONCENTRATE_API_KEY` in your environment, or launch OpenCode, run `/connect`, choose **Other**, and enter `concentrate` as the provider ID before entering your key.
  </Step>

  <Step title="Verify the connection">
    Run `opencode models`, select a `concentrate/` model with `/models`, and send a short prompt.
  </Step>
</Steps>

## Remove Concentrate AI

<Tabs>
  <Tab title="macOS / Linux / WSL">
    ```bash theme={null}
    curl -fsSL https://concentrate.ai/scripts/uninstall-opencode.sh | bash
    ```
  </Tab>

  <Tab title="Windows PowerShell">
    ```powershell theme={null}
    irm https://concentrate.ai/scripts/uninstall-opencode.ps1 | iex
    ```
  </Tab>
</Tabs>

The uninstall script removes the `concentrate` provider, any `concentrate/` default models, and the key stored in OpenCode. It leaves `CONCENTRATE_API_KEY` in your environment because other Concentrate integrations may use it.

## Use Different Models

Open `/models` inside OpenCode to choose another Concentrate model, or start OpenCode with a model ID:

```bash theme={null}
opencode -m concentrate/<model-id>
```

You can also run `opencode models` to see available IDs. Model availability and capabilities change over time; check the [models page](https://concentrate.ai/models) when choosing one for coding tasks.

## How It Works

The setup script adds `concentrate` as a custom OpenCode provider with `https://api.concentrate.ai/v1` as its base URL. It loads models from Concentrate's live catalog and stores your key in OpenCode's user auth file. On macOS and Linux, the auth file is normally `~/.local/share/opencode/auth.json` with file mode `600`.

The script backs up existing config and auth files before writing. If your global config is JSONC, setup asks before rewriting it as JSON; the backup retains its comments and formatting. Uninstall asks before rewriting a JSONC config too.

Billing and usage are managed through your Concentrate credits. You can review requests and spend in the [Concentrate dashboard](https://concentrate.ai/dashboard).

## Troubleshooting

<AccordionGroup>
  <Accordion title="Concentrate models are missing" icon="list">
    1. Run `opencode models` and look for IDs beginning with `concentrate/`.
    2. Confirm your global OpenCode config has a `concentrate` provider.
    3. Re-run the setup script to refresh the model catalog. If you use JSONC, approve the rewrite after reviewing the backup warning.
  </Accordion>

  <Accordion title="API key is missing or invalid" icon="key">
    Check that the key entered during setup is the one shown at [concentrate.ai/api-keys](https://concentrate.ai/api-keys). If you configured OpenCode manually, confirm `CONCENTRATE_API_KEY` is set or connect the `concentrate` provider through `/connect`. A 402 response means the key's account needs credits.
  </Accordion>

  <Accordion title="Requests cannot connect" icon="wifi">
    Confirm the provider base URL is `https://api.concentrate.ai/v1`, then check your internet connection and firewall. Try another model in `/models` to see whether the issue is specific to one model.
  </Accordion>

  <Accordion title="JSONC comments changed" icon="file-code">
    The setup and uninstall scripts can rewrite `opencode.jsonc` as JSON. They ask first and save a timestamped backup next to the original file. Restore comments or formatting from that backup if you need them.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="API Reference" icon="code" href="/docs/api-reference/introduction">
    Explore the Concentrate API.
  </Card>

  <Card title="Available Models" icon="layer-group" href="/docs/api-reference/endpoint/list-models">
    Browse the model catalog.
  </Card>

  <Card title="Auto Routing" icon="route" href="/docs/api-reference/endpoint/auto-routing">
    Learn about model selection and routing.
  </Card>

  <Card title="Get Support" icon="life-ring" href="mailto:support@concentrate.ai">
    Contact our support team.
  </Card>
</CardGroup>

## Feedback

If you encounter issues or have suggestions, email [support@concentrate.ai](mailto:support@concentrate.ai).
