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

# Use OpenCode with RunBridge AI

> Configure OpenCode with a custom OpenAI-compatible provider for RunBridge AI Chat Completions.

Connect [OpenCode](https://opencode.ai/docs/) using its custom provider support and the OpenAI-compatible Chat Completions adapter.

## Prerequisites

* Install OpenCode from its [official installation guide](https://opencode.ai/docs/#install).
* Create an active API key in the [RunBridge AI dashboard](https://runbridge.ai/console/token).
* Choose an exact [model ID](/overview/models) that supports **Chat Completions, streaming, and tool calling**. Replace `your-model-id` below.

The npm installation is:

```bash theme={null}
npm install -g opencode-ai
opencode --version
```

## Supply the API key

<Tabs>
  <Tab title="Bash / Zsh">
    ```bash theme={null}
    printf 'RunBridge AI API key: '
    read -rs RUNBRIDGE_API_KEY
    printf '\n'
    export RUNBRIDGE_API_KEY
    ```
  </Tab>

  <Tab title="PowerShell">
    ```powershell theme={null}
    $secureKey = Read-Host "RunBridge AI API key" -AsSecureString
    $env:RUNBRIDGE_API_KEY = [System.Net.NetworkCredential]::new("", $secureKey).Password
    ```
  </Tab>
</Tabs>

Start OpenCode from this terminal so the process can read the variable.

## Add a custom provider

Create `opencode.json` in your test project, or merge this into your existing configuration. For a configuration shared across your projects, use `~/.config/opencode/opencode.json`.

```json theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "runbridge": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "RunBridge AI",
      "options": {
        "baseURL": "https://api.runbridge.ai/v1",
        "apiKey": "{env:RUNBRIDGE_API_KEY}"
      },
      "models": {
        "your-model-id": {
          "name": "RunBridge AI coding model"
        }
      }
    }
  }
}
```

`runbridge` is a custom provider ID, not a built-in provider. The `models` key is the exact model ID sent to the API; `name` only controls its display label. Keep the base URL at `/v1` because the adapter appends `/chat/completions`.

OpenCode substitutes `{env:RUNBRIDGE_API_KEY}` at runtime. Keep that reference in the file instead of putting a secret into a project configuration. If you add context or output limits, use the chosen model's documented values rather than copying another model's limits.

<Note>
  This guide uses Chat Completions. For a Responses-only model, OpenCode documents the separate `@ai-sdk/openai` adapter. Select an adapter that matches the model's API format before using it.
</Note>

## Verify the connection

Start OpenCode in the directory containing your configuration:

```bash theme={null}
opencode
```

Run `/models` and select the RunBridge AI model. Ask: **Reply with “RunBridge connected” without running commands or changing files.** Check the request in the RunBridge AI usage records. Then verify tool calling in a disposable project before using the agent on real work.

## Troubleshooting

| Symptom | Check |
| - | - |
| Provider or model missing | Check JSON syntax, configuration location, and the custom provider/model names. Project settings can override global settings. |
| Missing key or 401 | Export `RUNBRIDGE_API_KEY` in the terminal launching OpenCode and check the key in the dashboard. |
| 404 | Use `/v1` in `baseURL`, omit the operation path, and choose a Chat Completions-compatible model. |
| Unsupported tools or context-length error | Check the chosen model's actual tool support and limits. |

See the official [custom provider](https://opencode.ai/docs/providers/#custom-provider) and [configuration](https://opencode.ai/docs/config/) documentation.

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@type": "TechArticle",
    "headline": "Use OpenCode with RunBridge AI",
    "description": "Configure OpenCode with a custom OpenAI-compatible provider for RunBridge AI Chat Completions.",
    "url": "https://runbridge.mintlify.site/integrations/opencode",
    "inLanguage": "en",
    "publisher": {
      "@type": "Organization",
      "name": "RunBridge AI"
    }
    }
    `}
</script>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.