Skip to main content
OpenCode is an advanced AI coding assistant. Configure it to use Codex-LB for account pooling and centralized usage tracking.

Endpoint

OpenCode uses the standard OpenAI-compatible /v1 endpoint.

Configuration

Edit your OpenCode config file at ~/.config/opencode/opencode.json:
Use this configuration when API key authentication is disabled (default):
~/.config/opencode/opencode.json

Configuration Fields

Multiple Models

You can configure multiple models from your Codex-LB instance:
Switch models in OpenCode using the model selector.

Preserving Default Providers

The configuration above adds codex-lb alongside OpenCode’s default providers (OpenAI, Anthropic, etc.).
If you use enabled_providers, you must explicitly list every provider you want to keep:
Providers not listed will be hidden.
To only use Codex-LB and disable other providers:

Verify Configuration

Test your setup:
Verify in the Codex-LB dashboard:
  1. Open http://localhost:2455
  2. Check Dashboard for usage metrics
  3. Confirm requests are being logged

Troubleshooting

The @ai-sdk/openai-compatible package may be missing:
Or if using OpenCode’s built-in package manager:
Ensure Codex-LB is running:
If using Docker:
API key auth is enabled but your key is missing or invalid:
  1. Verify the environment variable is set:
  2. Check the key is valid in the dashboard
  3. Ensure the apiKey field uses {env:CODEX_LB_API_KEY} syntax
  4. Restart OpenCode after setting the environment variable
If codex-lb doesn’t show up:
  1. Verify JSON syntax is correct (no trailing commas)
  2. Check OpenCode logs for config parsing errors
  3. If using enabled_providers, ensure codex-lb is listed
  4. Restart OpenCode
The requested model isn’t available:
  1. Check available models:
  2. Verify at least one account supports the model
  3. Update the models config to match available models

Advanced Configuration

Reasoning Effort Levels

For models with reasoning capabilities, configure the effort level:

Remote Access

If Codex-LB is running on a different machine:
When exposing Codex-LB remotely:
  • Always enable API key authentication
  • Use HTTPS with a reverse proxy
  • Configure firewall rules
  • See Production Deployment

Custom Headers

Add custom headers for advanced use cases:

VS Code Extension

If using OpenCode’s VS Code extension, it reads from the same ~/.config/opencode/opencode.json file. The configuration above should work for both CLI and VS Code usage. After updating the config:
  1. Reload VS Code window (Cmd/Ctrl + Shift + P → “Reload Window”)
  2. Check the OpenCode output panel for any errors
  3. Verify codex-lb appears in the model selector

Next Steps

API Keys

Create and manage API keys for authentication

Model Routing

Configure intelligent model routing

Chat Completions API

Explore the /v1/chat/completions endpoint

Usage Tracking

Monitor OpenCode usage in the dashboard