LLMRelay
LLMRelay runs a small HTTP server on your computer and sends text requests through the Codex or Claude CLI you already signed into. It never reads or stores their tokens. It has no Python package dependencies.
Start
Install Python 3.10+ and at least one vendor CLI: Codex CLI or Claude Code. LLMRelay uses a subscription account; API-key CLI logins are deliberately ignored.
From a clone of this repository, run:
python -m llmrelay
On first run, if neither CLI has a subscription login, LLMRelay opens the installed CLI's interactive sign-in flow. The vendor CLI handles the browser or terminal authentication; LLMRelay never receives the credential. After sign-in it starts the server and prints the endpoint. If the command runs without an interactive terminal, it prints the sign-in command to run separately.
Sign in or switch accounts at any time with python -m llmrelay login codex or python -m llmrelay login claude. Check both accounts with python -m llmrelay status. On some Windows systems, use py instead of python. The relay itself needs no install step. It runs until you press Ctrl+C. Default base URL: http://127.0.0.1:8765/v1; pass --port 9000 to change the port.
Use
OpenAI chat completions:
curl http://127.0.0.1:8765/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"messages":[{"role":"user","content":"Say hello"}]}'
Anthropic messages:
curl http://127.0.0.1:8765/v1/messages \
-H 'Content-Type: application/json' \
-d '{"messages":[{"role":"user","content":"Say hello"}]}'
OpenAI Responses also accepts a text input at POST /v1/responses.
Add "stream":true to stream text from either signed-in provider. This works on Chat Completions, Responses, and Anthropic Messages. The relay sends server-sent events in the format of the endpoint you call. For example:
curl -N http://127.0.0.1:8765/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"codex/default","stream":true,"messages":[{"role":"user","content":"Say hello"}]}'
Image input works in the final user message. Send a base64 data:image/png;base64,... URL in an OpenAI Chat image_url block or Responses input_image block. For Anthropic Messages, use an image block with a base64 source, media_type, and data. PNG, JPEG, WebP, and GIF are accepted; PNG is the safest choice across CLI versions. Remote image URLs and local file paths are not read; send the image bytes. Each request may include up to 20 images, 5 MiB per image and 20 MiB total. The full JSON body is limited to 32 MiB. Image detail values auto, low, and high are accepted but do not alter CLI image processing. Claude image input requires Claude Code 2.1.248 or newer for restricted file access.
Point an OpenAI SDK's base_url at http://127.0.0.1:8765/v1 and use any placeholder API key if the SDK requires one. Point an Anthropic SDK's base_url at http://127.0.0.1:8765. SDKs that require a model can use auto. The default loopback listener does not require authentication. Do not expose an unauthenticated listener through a tunnel or reverse proxy.
For a local container to reach the relay on its host, start with LLMRELAY_API_KEY=<random-secret> python -m llmrelay --host 0.0.0.0. Point the container at http://host.docker.internal:8765/v1 and send the same secret as a bearer token. A non-loopback bind requires a secret; keep that port confined to your trusted local network.
model is optional. The default is the signed-in Codex CLI's default model, or Claude's if Codex is unavailable. Use "model":"claude/sonnet", "model":"codex/<model-name>", or "provider":"claude" to route explicitly. Unprefixed claude-* and gpt-* names also route to the matching CLI. Set "reasoning_effort":"low" (or "reasoning":{"effort":"low"}) to choose effort when that model supports it. GET /health shows basic status, and GET /v1/models lists codex/<model> for every model your Codex account offers, as the CLI last fetched them: the GPT-6 family (codex/gpt-6-luna, codex/gpt-6-sol, codex/gpt-6-astra, codex/gpt-6.1-sol, codex/gpt-6.1-terra) needs Codex CLI 0.166 or newer (npm install -g @openai/codex@latest); an older CLI answers a GPT-6 request with an error that says to update it.
Scope
This is a small adapter, not a full implementation of either API. Each request starts a fresh CLI process, so even short prompts incur CLI startup time and agent context usage. It accepts system, user, and assistant text messages, plus images in the last user message. Responses text.format supports json_object and json_schema through prompt instructions; unlike native constrained decoding, schema adherence is best effort and clients should validate the result. It does not support tools or conversation IDs. Parameters that require those features return a JSON error. max_tokens and max_output_tokens are best-effort instructions to the CLI, not hard limits. Usage counts are taken from CLI output when present; a zero means that CLI did not report a count. Provider errors, timeouts, and busy limits return JSON errors with non-200 status codes. If a provider fails after streaming begins, the stream ends with an error event because HTTP status can no longer change.
Streaming uses Codex app-server or Claude Code's partial-message stream. Keep the vendor CLI current if streaming reports an unsupported option.
The CLIs own authentication and usage accounting. LLMRelay clears common API-key environment variables before launching them and only enables CLIs that report a subscription login. Check your provider's current plan terms and limits. OpenAI documents codex exec for scripted runs; Anthropic currently says claude -p and third-party app usage draw from subscription limits. This can change.
HTTP errors identify invalid requests or models (400), missing or expired subscription sign-in (401), provider usage limits (429), unavailable CLIs or services (503), and timeouts (504). Unexpected CLI failures return 502 without exposing raw CLI logs.
Run tests with python -m unittest discover -s tests.