# OpenCode

Source: https://docs.aicentos.com/en/clients/opencode

Language: en

> Use aicentos in OpenCode — connect a custom provider through a configuration file

OpenCode supports custom providers, so you can connect to the Codex Proxy service through a configuration file.

## Prerequisites

The OpenCode website provides an official install script, along with npm, bun, brew and other installation methods.

* If you use the official install script directly, you usually do not need to set up npm beforehand
* If you plan to install via npm, install Node.js and npm first
* If you plan to install via bun, install bun first

### Install Node.js (npm route)

The official Node.js download page is: [https://nodejs.org/en/download](https://nodejs.org/en/download)

* macOS / Windows: download and install the LTS version
* Linux: install using the distro instructions on that page

If you already have Homebrew on macOS, you can simply run:

```bash
brew install node
```

This installs both Node.js and npm.

After installing with your chosen method, confirm the corresponding commands work. For the npm route, check:

```bash
node -v
npm -v
```

**Note:** if you use a command-line environment on Windows, the official recommendation is currently to run OpenCode in WSL.

## Installation

The recommended approach is the install command from the OpenCode website:

```bash
curl -fsSL https://opencode.ai/install | bash
```

The OpenCode website also offers npm, bun, brew and other installation methods.

## Set the API Key

Use OpenCode's own connection / authentication flow:

```bash
opencode auth login
```

Alternatively, run /connect in the interactive UI and save this service as a custom provider.

If you prefer environment variables, have opencode.json read the standard variable name, for example:

```bash
export OPENAI_API_KEY="your_api_key_here"
```

## Configure opencode.json

Create opencode.json in the project root or your global configuration directory:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "aicentos": {
      "npm": "@ai-sdk/openai",
      "name": "aicentos",
      "options": {
        "baseURL": "https://aicentos.com/v1",
        "apiKey": "{env:OPENAI_API_KEY}"
      },
      "models": {
        "gpt-4o": {
          "name": "gpt-4o"
        }
      }
    }
  },
  "model": "aicentos/gpt-4o"
}
```

## Test

After starting OpenCode, run:

```
/models
```

You should see the models under aicentos.

## Notes

* Recommended order: configure the file manually first (opencode.json), then environment variables, and only then the cc-switch tool ([https://github.com/farion1231/cc-switch/releases](https://github.com/farion1231/cc-switch/releases))
* If you go through /v1/responses, the official OpenCode documentation recommends @ai-sdk/openai
* Only switch to @ai-sdk/openai-compatible if your endpoint only supports /v1/chat/completions
* No need to define project-private variables such as CODEX\_PROXY\_API\_KEY

## Related links

* Official website: [https://opencode.ai/](https://opencode.ai/)