Use third-party Codex API endpoints with API Key authentication
English | 简体中文
- ✅ Third-party Codex API Support - Connect to any compatible Codex API endpoint
- ✅ Simple API Key Authentication - No OAuth flow required
- ✅ Custom baseURL - Configure your own API endpoint
- ✅ Full Compatibility - Uses Codex Backend API format
- ✅ All Model Support - GPT 5.1/5.2 Codex all variants
- ✅ Prompt Caching - Reuse responses across requests
- ✅ Complete Tool Support - write, edit, bash, grep, glob, etc.
- ✅ CODEX_MODE - Codex-OpenCode bridge prompts (enabled by default)
Option A: Let an LLM do it
Paste this into any LLM agent (Claude Code, OpenCode, Cursor, etc.):
Install the opencode-openai-codex-key plugin and configure it with my third-party Codex API by following: https://raw.githubusercontent.com/NAXG/opencode-openai-codex-key/main/README.md
Option B: Manual setup
-
Add the plugin to your config (
~/.config/opencode/opencode.json):{ "plugin": ["opencode-openai-codex-key@4.4.0"] } -
Authenticate:
opencode auth login
Select: OpenAI → "Third-party Codex API (API Key + URL)"
Enter when prompted:
- API Base URL:
https://your-codex-api.com - API Key:
sk-...
- API Base URL:
-
Use it:
opencode run "write hello world to test.txt" --model=openai/gpt-5.1-codex-high
Installation Guide for LLM Agents
-
Edit the OpenCode configuration file:
- Linux/Mac:
~/.config/opencode/opencode.json - Windows:
%APPDATA%\opencode\opencode.json
- Linux/Mac:
-
Add the plugin to the
pluginarray:{ "plugin": ["opencode-openai-codex-key@4.4.0"] } -
Choose configuration style based on your OpenCode version and read the configuration from the corresponding URL
-
Merge the configuration into the user's
opencode.jsonfile, making sure to:- Keep the
"plugin": ["opencode-openai-codex-key@4.4.0"]declaration - Include all the
provider.openai.modelsfrom the configuration file - Keep the
provider.openai.optionssettings
- Keep the
Note: The baseURL and API Key will be set later through the authentication process, which saves them to ~/.opencode/openai-codex-auth-config.json automatically.
For OpenCode version 1.0.140 and later:
Configuration URL: https://raw.githubusercontent.com/NAXG/opencode-openai-codex-key/refs/heads/main/config/opencode-modern.json
Instructions:
- Read the complete configuration from the URL above
- Merge it with the user's existing
opencode.json - Ensure
"plugin": ["opencode-openai-codex-key@4.4.0"]is included in thepluginarray - Copy all the models and options from the configuration file
This configuration uses variants for a cleaner, more maintainable setup. Key features:
- Uses
variantsto define model variations (low/medium/high/xhigh) - Supports all GPT 5.1/5.2 Codex models
- Includes proper reasoning effort and summary settings
Usage with modern config:
opencode run "your prompt" --model=openai/gpt-5.2-codex-high
opencode run "your prompt" --model=openai/gpt-5.1-codex-mediumFor older OpenCode versions:
Configuration URL: https://raw.githubusercontent.com/NAXG/opencode-openai-codex-key/refs/heads/main/config/opencode-legacy.json
Instructions:
- Read the complete configuration from the URL above
- Merge it with the user's existing
opencode.json - Ensure
"plugin": ["opencode-openai-codex-key@4.4.0"]is included in thepluginarray - Copy all the models and options from the configuration file
This configuration uses individual model definitions for each reasoning level. Key features:
- Each reasoning level is a separate model (e.g.,
gpt-5.2-codex-low,gpt-5.2-codex-high) - Compatible with older OpenCode versions
- Includes all model variants explicitly defined
Usage with legacy config:
opencode run "your prompt" --model=openai/gpt-5.2-codex-high
opencode run "your prompt" --model=openai/gpt-5.1-codex-highAfter saving the config, run authentication to set up your API endpoint and key:
opencode auth loginSelect OpenAI → "Third-party Codex API (API Key + URL)" and enter:
- API Base URL: Your third-party Codex API endpoint (e.g.,
https://your-codex-api.com) - API Key: Your API key (e.g.,
sk-...)
This will automatically save your credentials to ~/.opencode/openai-codex-auth-config.json.
opencode run "Hello" --model=openai/gpt-5.1-codex-highAlready installed? Here's how to use it:
# Use with specific model
opencode run "your prompt" --model=openai/gpt-5.1-codex-high
# Use default model from config
opencode run "your prompt"
# Enable debug logging
ENABLE_PLUGIN_REQUEST_LOGGING=1 opencode run "your prompt"Logs are saved to: ~/.opencode/logs/codex-plugin/
- gpt-5.2 (none/low/medium/high/xhigh)
- gpt-5.2-codex (low/medium/high/xhigh)
- gpt-5.1-codex-max (low/medium/high/xhigh)
- gpt-5.1-codex (low/medium/high)
- gpt-5.1-codex-mini (medium/high)
- gpt-5.1 (none/low/medium/high)
See config/opencode-modern.json for complete configuration.
opencode auth login
# Enter baseURL and API Key when promptedCreate or modify ~/.config/opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-openai-codex-key@4.4.0"],
"provider": {
"openai": {
"baseURL": "https://your-codex-api.com",
"options": {
"reasoningEffort": "medium",
"reasoningSummary": "auto",
"textVerbosity": "medium"
},
"models": {
"gpt-5.1-codex-high": {
"name": "GPT 5.1 Codex High",
"limit": { "context": 272000, "output": 128000 },
"modalities": { "input": ["text", "image"], "output": ["text"] },
"options": {
"reasoningEffort": "high"
}
}
}
}
},
"model": "openai/gpt-5.1-codex-high"
}Then run:
opencode auth login
# Enter API KeySpecify your third-party Codex API endpoint. Can be configured via:
- Interactive Prompt (Recommended): Enter during authentication
- Plugin Config File:
~/.opencode/openai-codex-auth-config.json - Provider Config:
provider.openai.baseURLin opencode.json
Priority: Plugin config > Provider config > Default value
The plugin automatically transforms requests to: https://your-base-url/backend-api/codex/responses
Your third-party Codex API must:
- Endpoint Path:
/backend-api/codex/responses - Authentication: Bearer Token (
Authorization: Bearer YOUR_API_KEY) - Request Format: Codex Backend API format
- Response Format: SSE (Server-Sent Events)
This plugin:
- Intercepts requests from OpenCode's OpenAI SDK
- Rewrites URLs to your custom Codex API endpoint
- Transforms requests to Codex Backend API format
- Injects Codex system instructions
- Adds API Key authentication headers
- Converts SSE responses back to standard format
- Detailed Setup Guide:
THIRD_PARTY_SETUP.md - Configuration:
docs/configuration.md - Troubleshooting:
docs/troubleshooting.md - Architecture:
docs/development/ARCHITECTURE.md
Q: Getting 401 Unauthorized error? A: Check if your API key is correct.
Q: Getting Connection refused error? A: Verify that your baseURL is accessible.
Q: Model not found error?
A: Make sure to use the openai/ prefix (e.g., --model=openai/gpt-5-codex)
Q: Where is baseURL configuration saved?
A: ~/.opencode/openai-codex-auth-config.json
- This plugin is for connecting to your own or authorized third-party Codex API endpoints
- Please ensure you have permission to access the target API endpoint
- Different API providers may have different usage limits and pricing
MIT License
Modified from: numman-ali/opencode-openai-codex-key
Pure API Key Version - No OAuth Dependencies