OpenCode
Use aicentos in OpenCode — connect a custom provider through a configuration file
Last updated:
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
- 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:
brew install nodeThis installs both Node.js and npm.
After installing with your chosen method, confirm the corresponding commands work. For the npm route, check:
node -v
npm -vNote: 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:
curl -fsSL https://opencode.ai/install | bashThe OpenCode website also offers npm, bun, brew and other installation methods.
Set the API Key
Use OpenCode's own connection / authentication flow:
opencode auth loginAlternatively, 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:
export OPENAI_API_KEY="your_api_key_here"Configure opencode.json
Create opencode.json in the project root or your global configuration directory:
{
"$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:
/modelsYou 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)
- 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/