A small Go proxy that puts OpenAI-compatible Chat Completions and Responses models in Codex CLI's /model picker, alongside your ChatGPT subscription. Switch models within a conversation; no profiles or patched Codex required.
Proof of concept using Codex CLI 0.164.0. Live inference was tested on Debian Linux; macOS verification covers native lifecycle and the Codex picker without inference (see verification). YAML and TOML parsers plus a WebSocket client for checking Codex's loaded models; no database or JavaScript runtime for the proxy. The running proxy used about 15 MiB RSS during the initial Linux live tests. Windows support is not implemented.
The running container is codex-bridge-lab. It has Codex, the bridge, three external models, and your subscription login. The disposable provider key is stored only in its private bridge config, not in this repository or image.
docker exec -it codex-bridge-lab bash
codex-bridge status
cd /work
codex --no-daemonInside Codex, enter /model and select a0-qwen, a0-deepseek, a0-vision, or a subscription model such as GPT-6-Luna. External models appear first, in config order. To start with a specific external model, use codex --no-daemon -m a0-qwen.
codex-bridge edit # $VISUAL, then $EDITOR, then automatic editor detection
codex-bridge sync # validate config and write the model catalog
codex --no-daemon # load the current config without using the shared server
# Or, to use normal codex (this may interrupt active shared-server work):
codex-bridge sync --force
codex
codex-bridge restartRouting and body parameter changes are loaded on the next request. The bridge caches native model IDs and reloads the installed Codex catalog when a requested model is missing, so newly installed models work without restarting the proxy. Native OpenAI HTTP errors and connection failures clear the cache for the next request; failed inference requests are not replayed by the bridge. Unknown models are still rejected; a catalog read failure returns a retryable error. External requests do not read the Codex catalog. Run codex-bridge restart after changing the listen address, inherited environment variables, or the bridge binary. stop and status still work if you make a config syntax error or change the configured port.
Install Codex CLI 0.164.0, then install the latest bridge release on Linux or macOS:
curl -fsSL https://raw.githubusercontent.com/agent0ai/codex-bridge/main/install.sh | shThe installer detects amd64/arm64 and installs to ~/.local/bin/codex-bridge. To choose another binary path, append it using sh -s -- /path/to/codex-bridge. Downloads are staged beside the destination, checked with --version, then renamed into place; a failed download leaves the existing binary intact.
Alternatively, with Go 1.24.4 or newer, build in a source checkout:
go build -trimpath -ldflags="-s -w -X main.version=$(git describe --tags --always --dirty)" -o codex-bridge . &&
mkdir -p "$HOME/.local/bin" &&
install -m 755 codex-bridge "$HOME/.local/bin/codex-bridge"
export PATH="$HOME/.local/bin:$PATH"
codex-bridge edit # creates the initial config if missingIf needed, put the export PATH line in ~/.bashrc (Bash) or ~/.zshrc (Zsh, the macOS default) for future terminals. The default config is $XDG_CONFIG_HOME/codex-bridge/config.yaml on Linux (normally ~/.config/codex-bridge/config.yaml), and ~/Library/Application Support/codex-bridge/config.yaml on macOS. The proxy also supports an explicit file; quote paths with spaces, for example codex-bridge --config "$HOME/Library/Application Support/codex-bridge/config.yaml" start. Legacy .toml files remain readable when passed explicitly with --config. Codex's own ~/.codex/config.toml still uses TOML.
codex-bridge --version prints the binary's build version without requiring a config. status also shows this version. Release builds embed their Git tag; builds without -X main.version=... report dev.
init creates the example config; edit automatically does this when the file is missing, then opens it. Existing configs are preserved, including invalid configs that need fixing. start and sync require an existing config and never create one automatically.
edit honors $VISUAL, then $EDITOR. With neither set, it searches PATH in this order: micro, nano, mcedit, joe, nvim, vim, the system editor command, then vi. The first available executable is used. An explicit editor setting that fails produces an error rather than silently switching editors. If no editor is found or the selected editor fails, the error includes the full config path so you can edit it manually.
The initial config contains Venice DeepSeek V4.1 Flash (deepseek-v4-1-flash) under the alias a0-deepseek, with the tested reasoning parameter fix. Replace api_key: "..." with your key. To use an environment variable instead, comment out api_key, uncomment api_key_env: AGENT_ZERO_API_KEY, and export that variable before starting the proxy:
read -rs -p 'Provider API key: ' AGENT_ZERO_API_KEY; echo
export AGENT_ZERO_API_KEYThen start and sync:
codex-bridge start
codex-bridge sync
codex login # only if you have not already logged in
codex --no-daemonThe bridge uses Codex's existing subscription authentication and refresh logic. It never modifies auth.json or logs credentials. A subscription login is required for the normal mixed subscription/external setup. For external-only use without signing in, launch codex -c model_providers.codex-bridge.requires_openai_auth=false -m a0-deepseek.
See config.example.yaml for the initial DeepSeek V4.1 Flash config. The existing test container keeps its separate three-model config for the Qwen, DeepSeek, and vision tests. A model entry looks like:
listen: 127.0.0.1:8787
models:
- name: my-model # unique name in Codex's picker
model: actual-provider-model-id # defaults to name
base_url: https://provider.example/v1
api: chat # chat or responses
unknown_endpoints: auto # auto (default), native, or openai
api_key_env: MY_PROVIDER_KEY # or api_key: "literal key"
context_window: 131072 # defaults to 32768
vision: false # true for image-capable models
reasoning_efforts: [low, high] # omit if unsupported
drop_params: [parallel_tool_calls] # omit parameters the provider rejects
params:
temperature: 0.2
max_tokens: 8192
vendor_options:
thinking: trueparams accepts JSON-compatible YAML values and recursively merges them into the upstream JSON body after translation. Unknown config fields, duplicate keys, multiple YAML documents, and parameters with non-string map keys are rejected. drop_params removes top-level fields first. Routing and protocol fields (model, input, messages, tools, stream) are controlled by the bridge. Credentials use a Bearer token; omit both key settings for an unauthenticated local API. URLs may include an arbitrary path and query parameters, and may point to the API base or complete endpoint.
Changing context_window does not enlarge the provider's real context limit. Set it to a value the model actually supports. An API-compatible model still needs good tool-call support to perform coding tasks reliably.
| Command | Effect |
|---|---|
init |
Create the example config with private permissions; never overwrite an existing file. |
edit |
Create the example config if missing, then open it with your terminal editor. |
sync |
Validate config, generate a version-matched model catalog, and select the local bridge provider. |
sync --force |
Sync, then immediately invoke codex app-server daemon restart; active work may be interrupted. |
start |
Start one background proxy; repeated starts reuse the running instance. |
stop |
Stop the listener and allow active requests up to ten seconds to finish. |
restart |
Gracefully stop the proxy, then start with the current config and environment; also starts a stopped proxy. |
update |
Run the repository's installer to replace the current executable with the latest release, then restart the proxy using the new binary and the same config. |
status |
Show proxy health, configured model count, and whether Codex's provider/catalog match the bridge. |
serve |
Run in the foreground; stop with Ctrl-C. |
unsync |
Restore the prior provider/catalog settings while preserving unrelated config changes. |
sync writes $CODEX_HOME/config.toml and codex-bridge-models.json (normally under ~/.codex). It preserves unrelated settings and comments, creates config.toml.bridge-backup, and is idempotent. It refuses to overwrite an existing unmanaged codex-bridge provider or a separate custom model catalog. Profiles are never created. Model aliases must not collide with built-in model names.
After updating Codex, run sync to refresh the picker catalog. The bridge refreshes its model-ID cache on a missing model or after a native upstream error, but Codex's picker still needs to load the synced file. restart restarts only the bridge proxy; sync --force restarts Codex's shared server. Invalid config or missing environment-based API keys abort restart before stopping a working proxy.
codex-bridge update downloads install.sh from this repository's main branch and executes it only after the script download succeeds. It updates the executable you invoked, including custom install paths, and honors --config. Config and environment-based provider keys are validated before updating. The proxy restarts with your current shell environment and the existing ten-second graceful shutdown limit; longer active requests may be interrupted. A failed installer leaves the running proxy alone; if installation succeeds but restart fails, the command reports that the binary was updated. This command does not restart Codex's shared server or change its configuration.
Future compatibility migrations belong in install.sh: every install and update downloads a fresh copy, so migration logic can ship with future releases without requiring it in the already-installed binary. Keep migrations safe to rerun and preserve users' existing configuration and credentials. The script comes from main and installs the latest published release, so its migrations must remain compatible with that release.
Codex 0.164.0 can reconnect new terminals to an existing shared background server. That server keeps its startup model catalog, so closing and reopening the terminal does not refresh it. Use codex --no-daemon to load the synced files immediately, or run codex-bridge sync --force and reopen Codex. The force option restarts the shared server through Codex's own daemon command, which may interrupt active work and takes time to shut down gracefully. Normal sync never restarts it. If restarting fails, the command exits with an error and clearly reports that the files were still synced.
status verifies the provider, local token, listen address, and model catalog files, then connects to the running Codex server's Unix socket and queries its model/list API. It checks external model names, order, visibility, descriptions, reasoning options, and input modalities, including removed models still loaded by the server. It reports one result: synced, unsynced, or could not verify. A stopped/unreachable server, failed query, or malformed response produces could not verify; a confirmed difference produces unsynced. Reasons appear only when verification fails or finds a mismatch.
The query is read-only: it does not start/restart Codex or send inference requests. It follows pagination and has a ten-second deadline for the server check. Changing API keys or upstream parameters does not require sync; changing model metadata does. The API exposes picker metadata, not all internal settings such as retained context limits or provider credentials. Separate profiles, command-line overrides, and upstream model access are outside this check.
Version: v0.1.1
Running at http://127.0.0.1:8787
Config: /root/.config/codex-bridge/config.yaml
Models: 1 external
Codex sync: synced
Codex config: /root/.codex/config.toml
All selected models go through the proxy while synced, so keep it running. To return to your original setup:
codex-bridge unsync
codex-bridge stop
# Use codex --no-daemon, or restart the shared server and reopen Codex.
# If you last selected an external alias, choose a built-in model.The proxy binds only to a loopback IP and requires a random local token written by sync. Browser-origin requests are rejected. Third-party requests are built with only that model's credentials; subscription headers are sent only to fixed OpenAI destinations. HTTP redirects are not followed for third-party requests. Logs contain model, status, and timing rather than prompts or keys. The log is next to the config as config.yaml.log.
Supported: streamed text, multiple tool calls, tool results and multi-turn history, namespaced tools, custom/freeform tools (including apply_patch), reasoning summaries and replay, image URLs/data URLs, inline file data, structured-output schemas, usage counts, token-limit endings, upstream errors, cancellation, and native Responses forwarding. Summary-only reasoning is converted to text when crossing into Responses so OpenAI does not attempt to retrieve invented server-side item IDs.
Endpoints other than /v1/responses, /v1/responses/compact, and the local health/stop controls use the model's unknown_endpoints setting:
| Value | Destination |
|---|---|
native |
The model's configured base_url, using its provider credentials. |
openai |
OpenAI, using Codex's existing authentication. |
auto (default) |
Try native first. On a non-200 response or connection failure, try OpenAI if its endpoint differs and OpenAI credentials are available. Return the OpenAI response only if it is HTTP 200; otherwise return the first response/error. |
The model is identified by a model field in an uncompressed JSON or multipart body, or a model query parameter. A configured model name takes precedence; otherwise, an upstream model ID can select an entry if it is unique. Ambiguous IDs are rejected. Unconfigured models and requests without a model use the same OpenAI destination as native text requests, so there is no duplicate fallback call. OpenAI means https://chatgpt.com/backend-api/codex with ChatGPT-Account-ID, or https://api.openai.com/v1 for API-key requests. The bridge maps its /v1 prefix to the destination base; a configured base ending in /responses or /chat/completions uses sibling paths for auxiliary endpoints.
Auxiliary bodies, including their model IDs and multipart contents, pass through unchanged; no Chat Completions translation or parameter overrides apply. Requests are buffered up to 32 MiB to identify the model and replay the body. Compressed bodies remain unchanged and can select a configured model through the query parameter. Provider calls forward standard request metadata and only the configured provider credential; the local bridge token, cookies, and subscription credentials are never sent to a third party. Selected response statuses, headers, and streams are preserved. No output from a discarded attempt reaches the client. Because auto retries every status other than 200, including 201/202, it can repeat operations that have side effects; use native to disable fallback for those endpoints.
Native Responses requests retain hosted tool definitions, including web search and image generation. Support still depends on the upstream endpoint and account. If an older bridge returns unknown bridge endpoint, update its binary and run codex-bridge restart.
Codex Responses Lite can retain additional_tools catalog items in compacted history. When switching to a Chat Completions model, the bridge uses the request's current top-level tools array and skips these historical catalogs, preserving tool calls and results without re-enabling old tools or overwriting current schemas. A missing current tool array is rejected; external models generated by sync already have use_responses_lite: false. Native Responses requests retain their catalog items. If an older bridge reports cannot translate Responses input type "additional_tools", update the bridge binary and run codex-bridge restart, then retry the existing thread; no history deletion or Codex server restart is needed.
Local compaction deliberately sends no callable tools. The bridge omits tool_choice (auto or none) and parallel_tool_calls when the translated tool list is empty, including when only hosted web search was filtered out. Required or named tool choices without callable tools are rejected locally. This avoids provider errors such as When using tool_choice, tools must be set; restarting Codex does not fix older bridge versions that send this invalid combination.
This is a Codex-focused adapter, not a complete implementation of every Responses API feature:
- Chat Completions has no hosted OpenAI web search. The bridge removes that tool and tells the model it is unavailable. Use an MCP search tool or provider-specific
params. Subscription web search remains intact. - Audio, video, uploaded file IDs/URLs, computer-use tools, background jobs, and
previous_response_idstorage are not emulated for Chat Completions. Unsupported inputs fail explicitly. Codex's HTTP mode sends complete history and works without a response database. - Encrypted OpenAI reasoning cannot be converted to another provider's private reasoning format. Available summaries and visible conversation/tool history are preserved.
- Tool arguments are buffered until complete and validated before execution. Truncated or malformed calls produce an error rather than executing a partial command.
- Native subscription capabilities, eligibility, and rate limits still apply. The bundled model catalog includes models your account might not have. GPT-6.1-Sol reported capacity errors during the live tests; GPT-6-Luna completed the mixed-provider test.
- Switching models does not raise the destination model's context limit. Large or unusual provider-specific conversations need further testing. Do not assume every provider-specific extension is interchangeable.
Use an image-capable model with vision = true:
codex -m a0-vision --image screenshot.png -- 'Describe this screenshot.'
codex -m a0-qwen 'Read @notes.txt and summarize it.'Live checks passed for a single PNG, two PNGs in order, view_image tool output, a local text-file reference read through Codex tools, and retaining an image when switching external → subscription → external. Image/file media returned by tools is placed after all parallel tool results, because Chat tool messages accept only text. Inline Responses input_file.file_data maps to Chat's file content part; the destination must support that file type. This mapping has fixture coverage; PDF interpretation was not tested live.
The bridge preserves prompt_cache_key, prompt_cache_retention, prompt_cache_options, and content-part cache controls. It generates stable tool aliases and deterministic JSON, without inserting a new timestamp or random value into the upstream prompt on every request. Regression tests check that identical input produces identical output and adding a turn preserves the earlier message prefix.
The live test captured each upstream usage object during four consecutive turns in one Codex thread per model:
| Model | Turn | Input tokens | Cached input | Hit ratio |
|---|---|---|---|---|
| Qwen Coder | 1 | 74,666 | 0 | 0% |
| Qwen Coder | 2 | 74,697 | 74,640 | 99.92% |
| Qwen Coder | 3 | 74,728 | 74,672 | 99.93% |
| Qwen Coder | 4 | 74,759 | 74,704 | 99.93% |
| DeepSeek V3.2 | 1 | 68,518 | 0 | 0% |
| DeepSeek V3.2 | 2 | 68,544 | 68,416 | 99.81% |
| DeepSeek V3.2 | 3 | 68,570 | 68,416 | 99.78% |
| DeepSeek V3.2 | 4 | 68,596 | 68,480 | 99.83% |
Hit ratio is cached_input_tokens / input_tokens. Follow-up turns had weighted hit ratios of 99.93% for Qwen and 99.81% for DeepSeek; a final Qwen rerun measured 99.92%. Every earlier message, tool definition, and cache key stayed unchanged across those requests. The script uses a private proxy and an in-memory upstream tap; reports contain usage counters, not prompts or credentials. These were short answers to a fixed reference prompt, without tool execution in the cache measurement itself; tool execution is covered separately by the smoke tests.
Standard prompt_tokens_details.cached_tokens maps to Responses input_tokens_details.cached_tokens; DeepSeek's prompt_cache_hit_tokens is a fallback. Input/output detail fields are retained. Codex CLI reports cumulative thread usage after exec resume, so the test subtracts the previous total and checks that input, cached input, and output counts exactly match the upstream turn. See cache-verification.json for the original usage objects and verified deltas.
The supplied gateway replaces prompt_cache_key with its own stable account key. Preserving Codex's key fixes a portability issue for other providers, even though that gateway already supplied one. A later YAML-config verification run measured 36.28% weighted follow-up reuse, with an unchanged prefix and exact usage accounting; its raw usage is also in the report. Cache availability, retention, routing, model changes, compaction, and real prompt changes still affect reuse; these measurements do not guarantee a particular hit ratio for other workloads.
go test -race ./...
go vet ./...
# Real terminal picker regression; isolated daemon, dummy key, no model requests:
python3 tests/picker.py
docker build --build-arg VERSION="$(git describe --tags --always --dirty)" -t codex-bridge:proof .
docker run -d --name my-codex-bridge --init codex-bridge:proof
docker exec -it my-codex-bridge bash
# Run init/edit/start/sync and codex login inside this new container.No ports need publishing: Codex and the proxy share the container's loopback interface. This image uses Debian slim, a static Go bridge, the native Codex binary, Node for Codex's JavaScript tool, and basic coding tools. The image contains no credentials. Keep or back up the container's home directory before removing it.
The build/release workflow verifies branch pushes without publishing. A stable vMAJOR.MINOR.PATCH tag additionally publishes a release after all four native Linux/macOS amd64/arm64 jobs pass tests and build binaries with CGO disabled. The Mac jobs also run the isolated lifecycle and real Codex picker regression. The prepared release assets are codex-bridge-linux-amd64, codex-bridge-linux-arm64, codex-bridge-darwin-amd64 (Intel), codex-bridge-darwin-arm64 (Apple Silicon), checksums.txt covering all four, the MIT license, and third-party notices.
Release notes include commits since the previous stable tag. Assets are uploaded to a draft before publication; retries can complete a draft but cannot overwrite a published release. Older version tags do not replace the latest release used by the README's download links. The workflow uses GitHub's job token and needs no custom release secrets.
The live smoke test makes real provider requests and creates a temporary marker file using Codex tools. The cache script uses PyYAML, included in the image (apt install python3-yaml when running it separately on Debian):
docker exec codex-bridge-lab python3 /opt/bridge-smoke.py
# Or without a subscription login:
docker exec codex-bridge-lab python3 /opt/bridge-smoke.py --external-only
# Image/file checks, including subscription model switching:
docker exec codex-bridge-lab python3 /opt/bridge-attachments.py
# Four-turn cache checks with raw usage reports:
docker exec codex-bridge-lab python3 /opt/bridge-cache.py --model a0-qwen --report /tmp/cache-qwen.json
docker exec codex-bridge-lab python3 /opt/bridge-cache.py --model a0-deepseek --report /tmp/cache-deepseek.jsonThe picker regression requires a complete packaged Codex 0.164.0 installation for daemon management; pass --codex /path/to/package/bin/codex if your default CLI is a standalone binary, and --bridge /path/to/codex-bridge to test a build. It checks the default config path with spaces, editor invocation, background start/repeated start/stop, and status. It reproduces a stale catalog after normal sync, checks --no-daemon, then checks that sync --force makes the external model appear first in a normal terminal session. It also checks live status before/after restart, stale image support for an existing alias, and the stopped-server result. It gives subprocesses a temporary home and CODEX_HOME, dummy credentials, and an offline provider; existing configs and servers are untouched.
Unit tests cover translation, fragmented parallel tool calls, custom tools, reasoning, attachments, cache controls and accounting, stable prompt prefixes, JSON schemas, truncated streams, credential separation, native Responses forwarding, URL handling, validation, sync/unsync preservation, force restart, and restart failures. Live tests cover Qwen file edits and Python tests, DeepSeek reasoning and shell tools, image and file attachments, cache reuse, the interactive picker, and switching external/subscription models within one thread. See verification.txt for the recorded results.
Implementation references: Codex configuration, Codex v0.164.0 source, and MetaFARS/codex-relay (translation edge cases). The supplied gateway's /v1/models returned 400 Missing model ID; tested IDs were obtained from Venice's model catalog.