OpenCode

OpenCode is an open source AI coding agent for the terminal, desktop and IDEs. It isn't tied to one model vendor: it ships with 75+ providers and can connect to any OpenAI-compatible API.

Already have an account? Sign in

codelux.configExample
agent
opencode
endpoint
codelux.io/v1/messages
route
anthropic / claude-sonnet-5
status
available
  • OpenCode
Codelux Gateway
  • claude-sonnet-5
  • claude-opus-5-5
  • gpt-6-sol
  • DeepSeek-V41-Flash
  • kimi-k3
  • glm-5.3
Example: OpenCode connects to Codelux Gateway at codelux.io/v1/messages and uses anthropic / claude-sonnet-5. The same agent can switch between claude-sonnet-5, claude-opus-5-5, gpt-6-sol, DeepSeek-V41-Flash, kimi-k3, glm-5.3 and more.

How to use OpenCode with Codelux

About 10 minutes: install OpenCode → create a key in Portal → import with CC-Switch or add the provider with /connect + opencode.json → pick a model.

1. Install OpenCode

You need a modern terminal such as WezTerm, Alacritty, Ghostty or Kitty. On Windows, WSL is recommended.

Run the installer

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

Verify the installation

Run opencode in a project directory; the OpenCode interface means it is installed. Upgrade later with opencode upgrade.

Terminal
cd your-project
opencode
The OpenCode terminal interface
The OpenCode terminal UI. · OpenCode (MIT)

2. Set Codelux as the provider

Option A: import with CC-Switch. Option B: store the key with /connect and declare the Codelux provider and models in opencode.json.

Create a Codelux account and API key

  1. Go to Codelux Portal and create an account (existing users sign in).
  2. Pick a subscription plan or top up in Billing — any balance works for every agent.
  3. Open API Keys in the left menu and click Create New Key. Give it a name you will recognise, such as the agent's name.
  4. After it is created, copy the API key (starts with sk-) and the API base URL. The key is shown in full only once, so keep it somewhere safe.

Install CC-Switch

CC-Switch is an open-source (MIT) desktop app that manages API providers for Claude Code, Codex, Gemini CLI, OpenCode and more. It writes the configuration files for you, so you don't have to edit them by hand. Requirements: Windows 10+, macOS 12+, or Linux x86_64/ARM64 with glibc 2.35+ and WebKitGTK 4.1 (e.g. Ubuntu 22.04+, Debian 12+).

Install with Homebrew (recommended):

Terminal
brew install --cask cc-switch

Or download CC-Switch-v{version}-macOS.dmg from Releases. It is a Universal build signed and notarized by Apple, so it runs on both Apple Silicon and Intel Macs.

CC-Switch main window listing providers for Claude Code
CC-Switch main window: pick the app at the top, then enable a provider; the orange + button adds a new one.

Import Codelux into CC-Switch in one click

  1. Keep CC-Switch running (it registers the ccswitch:// link handler on first launch).
  2. In Portal, on the success page of the key you just created, find Import to desktop clients. It is only shown on desktop browsers.
  3. On the CC-Switch card, set Target app to OpenCode, then click Import.
  4. Your browser asks to open CC-Switch — allow it. CC-Switch shows a confirmation dialog with the provider name (Codelux), endpoint and key; confirm to add it.
  5. In CC-Switch, switch to OpenCode at the top and make sure the Codelux provider is enabled.

Prefer to add it by hand? In CC-Switch click the orange + → Custom, fill in Provider name (e.g. codelux.io), Website https://codelux.io, your API Key and the Request URL (the Codelux API base URL, no trailing slash), then click Add.

CC-Switch add provider form filled in for Codelux: provider name, website, API key and request URL
Adding Codelux manually in CC-Switch. For Claude Code the request URL is the host only, without a trailing slash.

In CC-Switch, OpenCode is a co-existing app: the card button is Add, several providers can stay configured, and you choose between them with /models. Reopen your terminal after importing.

(Option B) Store the key with /connect

  1. Start opencode and run /connect.
  2. Scroll to the bottom and choose Other.
  3. Enter the provider ID codelux — it must match the key used in opencode.json.
  4. Paste your Codelux API key. It is saved to ~/.local/share/opencode/auth.json.

(Option B) Add the provider to opencode.json

Edit the global config ~/.config/opencode/opencode.json (or opencode.json in a project root to scope it to that project):

~/.config/opencode/opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "codelux": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Codelux",
      "options": {
        "baseURL": "https://codelux.io/v1"
      },
      "models": {
        "claude-sonnet-5": { "name": "Claude Sonnet 5" },
        "gpt-5.5": { "name": "GPT-5.5" },
        "kimi-k3": { "name": "Kimi K3" },
        "deepseek-v4-flash": { "name": "DeepSeek V4 Flash" },
        "glm-5.2": { "name": "GLM-5.2" }
      }
    }
  },
  "model": "codelux/claude-sonnet-5"
}
  • npm: "@ai-sdk/openai-compatible" uses the Chat Completions API (/v1/chat/completions).
  • baseURL is the Codelux API base URL with /v1.
  • Each key under models is a model ID from Portal → AI Hub; name is only a display label.
  • model sets the default as provider/model.

Without /connect, add "apiKey": "{env:CODELUX_API_KEY}" to options to read the key from an environment variable.

3. Start using OpenCode

Pick a Codelux model, initialise the project and start working.

Pick a model

Run /models in OpenCode; a Codelux group appears — pick a model. You can also list models from the terminal:

Terminal
opencode models

Everyday commands

ActionWhat it does
/initAnalyse the project and create AGENTS.md (commit it to Git)
TabToggle Plan mode (read-only planning) and Build mode
@Fuzzy-search a file to add to the prompt
/undo · /redoUndo or redo the last change
/modelsSwitch model

See each request's model, tokens and charge in Portal → Logs.

FAQ

Codelux models don't show up in /models

Make sure the provider ID entered in /connect matches the key under provider in opencode.json (codelux), then restart OpenCode.

ProviderModelNotFoundError

The model reference is wrong. Use codelux/<model-id> and check the list with opencode models.

Requests fail with 401 or 404

401: check the key with opencode auth list or run /connect again. 404: baseURL must end with /v1.

Where are the logs?

In ~/.local/share/opencode/log/. Start with --log-level DEBUG for more detail.

Official references