Abstract
Codex CLI natively works with OpenAI‑style /v1/responses protocol, while most third‑party LLM platforms expose standard /v1/chat/completions endpoints. This protocol mismatch causes 404 errors if developers attempt direct integration with DeepSeek V4. Historical tutorials recommending wire_api = "chat" no longer function in current Codex releases. A translation bridge layer is mandatory to convert between Responses and Chat Completions schemas. This article walks through a complete six‑step deployment workflow built around LiteLLM, preserves official benchmark parameters and pricing data for DeepSeek V4, and explains configuration pitfalls. When working with multi‑model heterogeneous endpoints, developers may leverage an API gateway to unify request routing and protocol adaptation. 4sapi provides endpoint management capabilities that simplify multi‑provider testing in local development environments. Every command snippet, model specification and cost metric comes from real‑world validation.
1. Core Protocol Gap Between Codex CLI and Third‑Party LLM Platforms
The root obstacle stems from incompatible API schemas. Looking at codex‑rs/core/config‑schema.json within the open‑source Codex repository, the definition for wire_api accepts only one valid enum value: `responses`. This parameter tells Codex CLI which wire protocol the upstream provider implements. In older versions wire_api = "chat" was supported for Chat Compatibility mode, yet this branch has been fully removed from modern releases. Any guide referencing wire_api = "chat" is obsolete and will not work.
Codex CLI always sends requests toward /v1/responses. Most third‑party platforms including DeepSeek V4 implement the widely‑adopted /v1/chat/completions. No native /v1/responses endpoint exists on these services. Sending POST requests to /v1/responses returns 404 Not Found.
The table below demonstrates endpoint behaviour against 4sapi as the target upstream platform.
| Endpoint | HTTP Method | Outcome |
|---|---|---|
POST /v1/responses | POST | 404, returns {"message":"not found or method not allowed","status":false} |
POST /v1/chat/completions | POST | 200 OK, returns valid chat‑completion JSON payload |
Directly assigning third‑party base URL into Codex CLI base_url field triggers automatic requests to the non‑existent /v1/responses route, resulting in guaranteed failure. A translation bridge is required to accept Codex‑formatted Responses traffic and translate payloads to Chat Completions for upstream inference.
2. DeepSeek V4 Model Variants, Specifications and Pricing
DeepSeek V4 provides three production‑ready model variants, documented within official API references. Key technical parameters are summarised below.
| Model ID | Version | Context Window | Max Output Tokens | Concurrent Request Quota |
|---|---|---|---|---|
| deepseek‑v4‑flash | DeepSeek‑V4‑Flash‑0731 | 1 000 000 | 384 000 | 2500 |
| deepseek‑v4‑pro | DeepSeek‑V4‑Pro‑0813 | 1 000 000 | 384 000 | 500 |
| deepseek‑v4‑flash‑vision‑exp | DeepSeek‑V4‑Flash‑Vision‑Exp | 1 000 000 | 384 000 | 2500 |
Pricing differentiates off‑peak and peak hours. Peak window is defined as UTC 01:00‑04:00 and 06:00‑10:00. Flash and vision‑exp share identical price tables. Pro variant costs approximately three times higher. All models support one‑million‑token context and 384 000 maximum output length. Flash delivers high concurrency at lower cost and suits most engineering tasks. Pro is reserved for large‑scale code refactoring and complex multi‑layer architecture work.
>
> Important naming note: Platform‑returned model identifiers carry deepseek/ prefix. When configuring local clients, developers must match exact IDs returned by the model‑list API; manual name editing causes runtime failures.
3. Six‑Step End‑to‑End Integration Workflow
The complete request flow runs: Codex CLI → LiteLLM translation bridge layer → 4sapi upstream model platform.
Step 1: Retrieve API Key and set environment variable
Fetch your API access key from platform console. Store credentials within environment variables instead of hard‑coding inside configuration files. LiteLLM supports reading secrets via OS environment.
Step 2: Validate upstream endpoints and model identifiers
Verify available model list over HTTP request. Confirm that /v1/responses returns 404 to confirm bridge requirement.
Receiving 404 confirms you cannot skip the translation bridge.
Step 3: Configure LiteLLM bridge with protocol translation
The critical toggle is use_chat_completions_api: true. When enabled, LiteLLM converts incoming /responses format into standard /chat/completions requests toward upstream providers. Create litellm.yaml.
Start LiteLLM local service instance:
Observe log message Uvicorn running on http://0.0.0.0:4000 to confirm successful startup.
Step 4: Validate bridge layer independently
Test bridge endpoint before touching Codex CLI configuration. Isolating validation helps separate bridge‑side bugs from Codex misconfiguration.
A healthy response returns HTTP 200, conforms to Responses schema: {"object":"response","status":"completed"}. The JSON payload includes usage block containing reasoning_tokens. DeepSeek V4 outputs reasoning tokens for internal thought steps, these tokens are also billed as output tokens during cost calculation.
Step 5: Configure Codex CLI config.toml
Edit ~/.codex/config.toml. Remember wire_api must equal `"responses"`. Setting wire_api = "chat" causes failure.
Export environment variable matching env_key entry in config:
Key configuration notes:
base_urlmust terminate with/v1. Codex appends/responsessuffix automatically.- Credentials are injected via environment variables; never hard‑write secrets inside TOML files.
wire_api="responses"is the single permitted value for modern Codex CLI.
Step 6: Manage multiple‑model setups with profiles
Use Codex profile feature to maintain separate configurations for Flash and Pro without manual file edits.
Invoke target profile at runtime:
For safe testing without polluting local home‑directory config, set temporary $CODEX_HOME:
4. Configuration‑layer caveats
Codex CLI treats model_providers as user‑scope configuration. These settings belong inside ~/.codex/config.toml. Avoid committing this file into shared source repositories. Secrets and provider endpoints are environment‑specific and must not be version‑controlled. Profiles can also reside in standalone files under $CODEX_HOME/<profile‑name>.config.toml.
5. Comparison of three integration approaches
| Approach | Workable | Notes |
|---|---|---|
Codex CLI directly calls upstream /v1/chat/completions | ❌ Not workable | wire_api only supports responses. Codex always targets /v1/responses. |
Codex CLI sends /v1/responses directly to upstream platform | ❌ Not workable | Upstream returns HTTP 404 error. |
| Codex CLI → LiteLLM bridge → upstream platform | ✅ Valid solution | Enable use_chat_completions_api: true. Verified in practical testing. |
>
> Note: The built‑in codex‑responses‑api‑proxy component inside Codex source repository strictly forwards POST /v1/responses traffic only toward official OpenAI endpoints. It cannot be repurposed for generic third‑party model services.
6. Cost‑optimisation advice after successful integration
Three actionable practices reduce inference spend with DeepSeek V4 on this stack.
- Prioritise
deepseek‑v4‑flashfor most daily tasks. Flash provides identical context window and maximum output length versus Pro, delivers 2500‑way concurrency, while costing around one‑third of Pro pricing. Reserve Pro for heavy refactoring and architecture‑level design assignments. - Leverage cached‑input pricing. Cache‑hit input token cost is far cheaper than cache‑miss cost. Group related work into single continuous sessions to maximise cache reuse. Avoid spawning frequent short‑lived independent sessions.
- Schedule large batch jobs to off‑peak hours. Official peak window maps roughly to morning and afternoon Beijing local hours. Schedule non‑urgent heavy workloads outside peak UTC windows to take advantage of discounted off‑peak rates.
Always include reasoning_tokens in cost estimation. DeepSeek V4 deducts reasoning tokens against output‑token quota. Ignoring reasoning token consumption will lead to significant underestimation of real‑world billing.
7. Frequently encountered issues
Q: Tutorials online recommend `wire_api = "chat"`, why does Codex report errors?
A: The "chat" enum value has been removed in current Codex CLI releases. Only wire_api = "responses" remains valid. Those articles reference deprecated old releases and are no longer applicable.
Q: Is LiteLLM the only viable bridge solution?
A: Any custom translation service can fill this protocol‑translation role. Developers may write custom middleware converting Responses request/response schema to Chat Completions format. Custom implementations must handle streaming chunks, tool invocation, and reasoning‑token metadata parsing, increasing engineering overhead. LiteLLM delivers these capabilities out‑of‑the‑box.
Q: Does bridge middleware add substantial latency?
A: Local LiteLLM forwarding overhead is minimal. Most latency originates on model inference side. Validate streaming behaviour end‑to‑end; confirm incremental chunk output instead of monolithic final‑response returns.
Q: Model cannot be found error after configuration.
A: Two common causes: missing openai/ prefix inside LiteLLM config, or mismatched model identifier. Copy exact model ID returned by upstream /v1/models endpoint. Local aliases defined under model_name in LiteLLM config are independent of upstream real identifiers.
Q: Binary installation errors for Codex CLI?
A: spawn ENOENT errors relate to npm binary package installation corruption. Re‑install @openai/codex. This is unrelated to bridge‑layer or upstream‑model configuration.
8. Conclusion
The fundamental integration challenge between Codex CLI and DeepSeek V4 boils down to protocol incompatibility. Codex CLI exclusively consumes the Responses API schema, whereas DeepSeek V4 exposes Chat Completions. A translating bridge component sits in‑between to translate request‑response payloads. The six‑step workflow described achieves stable operation, retains full model capabilities including reasoning‑token metadata and high‑concurrency Flash‑variant throughput.
Before opening production workloads, validate endpoints, model identifiers and token‑usage metrics with curl‑based manual testing. Always treat secrets as environment variables rather than static configuration entries.
International access: https://4sapi.com
Domestic access: https://4sapi.cn




