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.3.tar.gz (60.9 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.3-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: claude_openai_proxy-0.1.3.tar.gz
  • Upload date:
  • Size: 60.9 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.3.tar.gz
Algorithm Hash digest
SHA256 a52eb9c39339059477da0d50b38ef56a27714dec2c2b4bc0661a928a7bd80039
MD5 a806e6fe44b65d460420dfc6f51ce93a
BLAKE2b-256 9540f267d3a14b919b0d63c74e770887bb6ab4ef970ab0207b11e9444c370ae3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: claude_openai_proxy-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 89b0ea75cc848f3c914f1c28437268cc9355eca0ae40aa6278919d17fb82f6c1
MD5 ce620ef6db05455f7c1abbb31c718c17
BLAKE2b-256 318eb921ebb249ef0a36ee9ae3574412dc1b6b46e8b3b082fdce6cc8157424cb

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