Skip to main content

Thin OpenAI-compatible API proxy backed by Claude Code CLI

Project description

Claude OpenAI Proxy

A thin Python proxy that wraps the Claude Code CLI (claude -p) and exposes an OpenAI-compatible /v1/chat/completions API.

Claude runs as a clean LLM — all built-in tools are disabled. A behavioral shim is injected into the system prompt so Claude behaves as a stateless text-in / text-out language model.

Prerequisites

  • Claude Code CLI installed and authenticated (claude must be on PATH)
  • Python 3.11+

Install

pip install --user claude-openai-proxy

Make sure ~/.local/bin is in your PATH.

Or from source:

cd claude-openai-proxy
uv sync

Run

claude-openai-proxy                          # localhost:1234
HOST=0.0.0.0 PORT=5000 claude-openai-proxy   # all interfaces, custom port

Or from source:

uv run python main.py

Endpoints

Method Path Description
GET /health Health check
GET /v1/models List available Claude models
POST /v1/chat/completions Chat completions (streaming + sync)

Development

uv sync --group dev

Lint

uv run ruff check .          # check for issues
uv run ruff check --fix .    # auto-fix issues

Format

uv run ruff format .         # format all files
uv run ruff format --check . # check without writing

Test

uv run pytest               # run all tests
uv run pytest -v            # verbose output

Timeouts & Disconnect Handling

The proxy guards against runaway requests with two independent timeouts and automatically cleans up when a client disconnects.

Guard What it does
Per-line timeout (CLAUDE_TIMEOUT) Kills the CLI if a single line of output takes longer than this many seconds. Catches hung processes.
Total request timeout (CLAUDE_MAX_REQUEST_TIMEOUT) Kills the CLI once the overall wall-clock time for the request exceeds this limit, regardless of per-line activity.
Client disconnect For both streaming and non-streaming responses the proxy polls for client disconnection and stops the underlying work immediately.

Environment Variables

Variable Default Description
HOST 127.0.0.1 Server listen address
PORT 1234 Server listen port
CLAUDE_TIMEOUT 300 Max seconds to wait for a single line of output
CLAUDE_MAX_REQUEST_TIMEOUT 600 Max total wall-clock seconds per request
DISABLE_BUILTIN_TOOLS 1 Set to 0 to keep Claude CLI built-in tools enabled

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claude_openai_proxy-0.1.2.tar.gz (58.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_openai_proxy-0.1.2-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file claude_openai_proxy-0.1.2.tar.gz.

File metadata

  • Download URL: claude_openai_proxy-0.1.2.tar.gz
  • Upload date:
  • Size: 58.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for claude_openai_proxy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3acccb86070f757907ed2f02a080821dadfedd5506809a063b8311425ea8fa89
MD5 6f101878e42dcfee682856e9ddc5ec83
BLAKE2b-256 a36a1ba6d0213fbd25f7a4ad104ef9d916e254a6224a9604fadffa2a9f730906

See more details on using hashes here.

File details

Details for the file claude_openai_proxy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: claude_openai_proxy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for claude_openai_proxy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c403f5e966139884ee6c667a943fcb5f5a29c1a486a86a7bc1230b3ed27d965d
MD5 7dbe5d2ffabf9f63027ee88a44121744
BLAKE2b-256 202f6f58199a600773d33dc6af10c1192c763c23dfe9821b138757f6148e43de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page