Connecting External Models to Codex Desktop: A Protocol Bridging Guide
This article explains how to connect Codex-like desktop tools to model services that only support the Chat Completions protocol using a third-party bridging package. It covers protocol differences, environment setup, configuration, and troubleshooting to help you run the bridge service locally.
I. Conclusion and Scope
This article introduces how to connect Codex-like desktop tools to model services that only support the Chat Completions protocol. The solution relies on a third-party bridging package; it is not an official OpenAI or Anthropic solution. The steps are written using a Windows environment as an example. Because software versions change, you should re-verify the setup after upgrading any component.
If you are using Claude Code, it calls the Anthropic Messages API, which is different from the protocol conversion method discussed here. This article does not apply to that scenario.
II. Differences Between the Two Protocols
The core problem the bridge service solves is the inconsistency in request and response formats. The table below lists several key differences.
| Comparison Item | Responses API | Chat Completions API |
|---|---|---|
| Request Body | Uses the input field to carry the input |
Uses the messages array to carry the conversation |
| Tool Definition | name and parameters are placed directly on the tool object |
Function information is wrapped in the function field |
| Tool Result Return | Returned as a specific event item | Returned as a message with the role tool |
| Streaming Return | Finely divided event types | Returned in segments as data chunks |
These differences mean that sending a Responses request directly to a Chat Completions endpoint will typically result in a “bad request format” or “streaming parsing failure” error. Desktop tools’ configuration interfaces rarely tell you exactly which field caused the problem, so an intermediary translator is necessary.
III. What the Bridge Service Does
The bridge service is a lightweight proxy running on your local machine. Its workflow is divided into three steps: receive, convert, and forward.
First, the bridge service listens on a fixed local port (8787 in the example) and exposes an entry point in the Responses format. The desktop tool sends requests to this endpoint, believing it is communicating with a standard Responses service.
Second, the bridge service maps the Responses request to the Chat Completions structure. This step handles four types of alignment: fields for role and content, converting tool definitions from a nested structure to a flat structure, the stream toggle and related parameters, and mapping or passing through the model name.
Third, the bridge service sends the request to the upstream Chat Completions endpoint. After receiving the response, it translates it back into a Responses output. In streaming scenarios, it parses the upstream data chunks block by block, repackages them into Responses event formats, and pushes them to the desktop tool.
The benefit of this design is that the desktop tool does not need to know the protocol details of the upstream service. Another advantage is that the bridge service runs locally, keeping your API keys and request content entirely under your control.
IV. Preparing the Environment
Before installation, ensure the following versions meet the requirements:
- Node.js 20.0.0 or higher
- npm 10.0.0 or higher
- Rust toolchain 1.85.0 or higher, used to compile the core binary of the bridge service
Run the following commands to check your versions:
node -vnpm -vrustc --versioncargo --version
If Rust is missing, download the installer from the official site rustup.rs rather than obtaining it from other sources. After installation, refresh your environment variables, reopen your terminal, and run the check commands again.
V. Verify Package Source Before Installation
This bridge package is published by a third party. Check its information before installation:
npm view @heungtae/codex-chat-bridge
Focus on confirming three things: whether the repository address is accessible, whether the license is acceptable, and whether there have been recent version updates. If the package page lacks a repository address or has been unmaintained for a long time, it is recommended to postpone using it. If the publisher provides a checksum, compare it after downloading.
Once confirmed, proceed with global installation and binary compilation:
npm install -g @heungtae/codex-chat-bridgecd (npm root -g)\@heungtae\codex-chat-bridgenpm run build:bridge
The compiled artifact will be located in the target\release\ directory. Copy the codex-chat-bridge.exe file to a directory in your PATH (for example, the Node.js installation directory), and then verify it:
codex-chat-bridge --version
If it prompts that the command cannot be found, it usually means PATH does not include the target directory, or the terminal has not been reopened.
VI. Writing the Configuration File
The configuration file for the bridge service is located in the .config/codex-chat-bridge/conf.toml directory under your user home folder. On Windows, this corresponds to %USERPROFILE%\.config\codex-chat-bridge\conf.toml. Below is an example:
[routers.bailian]# Inbound URL: the address the desktop tool accessesincoming_url = "http://127.0.0.1:8787/bailian/v1/responses"# Upstream URL: the full Chat Completions endpoint provided by your model service providerupstream_url = "https://your-provider.example.com/v1/chat/completions"# Upstream API type, fixed to chatupstream_api_type = "chat"
Please note the following:
- Use
127.0.0.1for the host part of theincoming_url. Do not use0.0.0.0, otherwise other devices on the same network might access this port. - The
upstream_urlshould be the full endpoint found in your provider’s documentation, and you must confirm that the endpoint supports streaming returns. - Do not write the upstream API key directly into
conf.toml. Some versions read the key via environment variables, such asCODEX_BRIDGE_API_KEY(refer to the package documentation for the exact variable name). In PowerShell, you can set the variable for the current session like this:
$env:CODEX_BRIDGE_API_KEY = "your-api-key"
For long-term use, add a user-level variable in your system’s environment variable settings instead of hardcoding the key in a script.
Regarding key management, also ensure the following:
- Do not commit configuration files to a Git repository. If the directory is already under version control, add
conf.tomlto.gitignorefirst. - Restrict access permissions for the configuration file. On macOS or Linux, execute
chmod 600 ~/.config/codex-chat-bridge/conf.toml. On Windows, in the file properties’ Security tab, keep read/write permissions only for the current user. - Before sharing logs or screenshots, check for any
Authorizationheaders or key fragments and remove them if present.
VII. Starting and Verifying
Start the bridge service in one terminal:
codex-chat-bridge
In another terminal, send a test request directly to the inbound address using curl. Windows includes curl.exe, so you must explicitly include the extension:
curl.exe -N http://127.0.0.1:8787/bailian/v1/responses -H "Content-Type: application/json" -d "{\"model\":\"your-model\",\"input\":\"Introduce yourself in one sentence\",\"stream\":true}"
The model must match the model name provided by your upstream service. The -N parameter disables output buffering, making it easier to observe streaming returns. The expected result is that event data appears progressively in the terminal and finishes normally. If you change stream to false, it should return a complete JSON object.
Once the test passes, configure the desktop tool. In the tool’s settings, some require the full address, while others only need the base URL. If the full address is required, enter the complete value of incoming_url. If only the base address is required, remove the /responses suffix at the end, depending on the tool’s specific instructions.
If the curl test fails, you can troubleshoot using the table below:
| Symptom | Common Cause | Troubleshooting Method |
|---|---|---|
| 401 | Missing or incorrect API key | Ensure the environment variable name is correct and set it in the same terminal where the bridge service is started |
| 404 | Request path does not match configuration | Check the path character by character against incoming_url |
| 400 | Request body does not conform to Responses format | View the pre- and post-conversion content output by the bridge service and check the model and input fields |
| 502 or Timeout | Upstream unreachable or network interrupted | Use curl to request the upstream endpoint directly to confirm network and address availability |
| Streaming parsing failure | Upstream did not return in a stream, or stream parameter was not passed through |
Change stream to false and compare the non-streaming result |
During troubleshooting, first use curl to confirm whether the bridge service itself is working properly. If curl succeeds but the desktop tool fails, the problem likely lies in the tool’s address or API key settings. If curl also fails, check the upstream service and configuration layer by layer.
VIII. Long-Term Usage Notes
Version Matching. The bridge package, desktop tool, and upstream service are all frequently updated. Protocol fields may be added or removed, so you should run the tests from Section VII again after upgrading.
Streaming Stability. Long connections are susceptible to network fluctuations. If streams frequently disconnect, you can appropriately increase the timeout parameter in the bridge configuration. Temporarily switching to non-streaming mode during troubleshooting can quickly help distinguish between network issues and conversion issues.
Tool Calling Semantics. If the desktop tool relies on tool calling to read/write files or execute multi-step tasks, you should specifically test it with a small task, such as asking it to read a local file and summarize its contents. Passing a standard conversation test does not guarantee that tool calling works correctly.
Port and Network Security. The bridge service should only listen on 127.0.0.1. Do not expose this port via a router or intranet penetration.
