Skip to content

Latest commit

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

codex-proxy

CI

A single-file bridge from the Anthropic Messages API to the OpenAI Responses API — run Claude Code (or any Anthropic-API client) on gpt-5.6-* models while keeping the client's own tools, skills and MCP servers.

One file, zero dependencies, Node ≥ 22, no build step:

OPENAI_API_KEY=sk-... PORT=4001 ./codex-proxy.ts
# then point the client at it:
ANTHROPIC_BASE_URL=http://127.0.0.1:4001 claude --model codex-sol

Why the Responses API, not chat/completions

gpt-5.6-* rejects function tools on /v1/chat/completions when reasoning_effort is set — the API answers "Function tools with reasoning_effort are not supported … use /v1/responses or set reasoning_effort to 'none'". Killing reasoning defeats the point of the model, so the bridge speaks Responses upstream and Messages downstream.

What it translates

Anthropic (downstream)OpenAI Responses (upstream)
messages[] with text / image / tool_result blocksinput[] items (input_text, input_image, function_call_output)
tool_use blocksfunction_call items
tools + tool_choicetools (non-strict) + tool_choice
systeminstructions
SSE streaming eventsrebuilt event-by-event (message_startcontent_block_*message_stop)
/v1/messages/count_tokenslocal estimate (client uses it only for context-pressure hints)

Carrying reasoning across tool rounds

Responses-API reasoning items are opaque: the model returns an encrypted blob that must be echoed back verbatim on the next turn, or the chain of thought is lost. An Anthropic-API client only round-trips content blocks it received — so the bridge smuggles the blob through a thinking block's signature field and rebuilds the reasoning item on the way back upstream. Disable with CODEX_CARRY_REASONING=0.

Configuration

Env varDefaultMeaning
OPENAI_API_KEY— (required)upstream auth
PORT40010 picks a free port; prints codex-proxy ready port=<n> on stderr
CODEX_UPSTREAMhttps://api.openai.com/v1/responsesupstream URL
CODEX_EFFORTmediumreasoning.effort for gpt-5.6-*
CODEX_CARRY_REASONINGon0 disables the encrypted-reasoning round-trip
CODEX_FALLBACK_MODELgpt-5.4-miniwhere background calls (titles, quota probes) land instead of 400-ing
CODEX_DEBUGoff1 logs request/response shapes to stderr

Model aliases: codex-lunagpt-5.6-luna, codex-solgpt-5.6-sol, codex-terragpt-5.6-terra; any gpt-* name passes through unchanged.

Tests

npm test

The translation layer is exported from codex-proxy.ts, and the server only starts when the file is the process entry point — so node --test can pin every conversion without opening a socket or calling the upstream API. The streaming tests replay a recorded Responses SSE stream from test/fixtures/, re-fed at several chunk sizes to prove events that span a socket boundary are reassembled.

Non-goals

Auth beyond a bearer key, retries, rate limiting, multi-tenant use. It is a localhost bridge (127.0.0.1 only) meant to sit next to the client process that spawns it.

License

MIT

About

Anthropic Messages API to OpenAI Responses API bridge in a single dependency-free TypeScript file

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages