RichardAtCT/claude-code-openai-wrapper

OpenAI API-compatible wrapper for Claude Code

Claude Code OpenAI API Wrapper

What it is – A self‑hosted server that makes Anthropic’s Claude Code models look like the OpenAI API. By running the wrapper you can keep using any existing OpenAI client library (Python SDK, curl, etc.) while the requests are actually routed to Claude Code via the official Claude Agent SDK.

Why it matters – Many tools, notebooks and integrations are built for the OpenAI endpoint (/v1/chat/completions). Re‑implementing them for Claude would be tedious. This wrapper lets you swap in Claude Code with a single configuration change, while still getting:

  • Real‑time cost and token usage from the Claude SDK
  • Session continuity (conversation memory) across calls
  • Optional tool usage (file read/write, bash, etc.)
  • Multi‑provider authentication (Anthropic API key, AWS Bedrock, Google Vertex AI, or Claude CLI)

Key features

  • OpenAI‑compatible endpoints – /v1/chat/completions and /v1/messages (Anthropic style) work with streaming or non‑streaming responses.
  • Live model discovery – When ANTHROPIC_API_KEY is present the wrapper fetches Anthropic’s current model list (cached for an hour) and automatically picks the newest Sonnet model as the default.
  • Fast default mode – Tools are disabled by default, giving a 5‑10× speed boost for pure chat use. Tools can be enabled per request.
  • Session management – Include a session_id to keep conversation history; endpoints exist to list, inspect and delete sessions. Sessions expire after 1 hour of inactivity.
  • Multi‑provider auth – Detects and uses Claude CLI auth, raw API key, AWS Bedrock, or Google Vertex AI without extra code.
  • Interactive landing page – A built‑in UI at http://localhost:8000/ lets you explore the API, copy commands, and toggle light/dark themes.
  • Rate limiting & optional API‑key protection – Prevents abuse and lets you secure the server for remote access.
  • Docker support – Official Dockerfile and a Docker‑Compose example for quick deployment.

Getting started (under 2 min)

# Clone and install
git clone https://github.com/RichardAtCT/claude-code-openai-wrapper
cd claude-code-openai-wrapper
poetry install   # creates a venv and pulls the Claude Agent SDK

# Authenticate (pick one)
export ANTHROPIC_API_KEY=your‑key   # or `claude auth login`

# Run the server (development mode with hot‑reload)
poetry run uvicorn src.main:app --reload --port 8000

# Test with curl
curl http://localhost:8000/v1/models

The server will now accept OpenAI‑style calls at http://localhost:8000/v1/chat/completions.

Typical usage with the OpenAI Python SDK

from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1")
resp = client.chat.completions.create(
    model="claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Write a Python hello‑world script"}],
    stream=False,
)
print(resp.choices[0].message.content)

Add extra_body={"enable_tools": True} to let Claude actually read/write files, or pass extra_body={"session_id": "my‑session"} to keep context.

Production considerations

  • Use the Docker image (docker build -t claude-wrapper .) for isolated deployment.
  • Set API_KEY or enable the interactive key prompt to protect the endpoint when exposing it beyond localhost.
  • Adjust rate‑limit env vars (RATE_LIMIT_CHAT_PER_MINUTE, etc.) as needed.
  • For enterprise setups you can point the wrapper at AWS Bedrock or Google Vertex AI by setting CLAUDE_AUTH_METHOD.

Status – Marked Production Ready. All core endpoints are tested, streaming works, and the wrapper includes health, version and authentication‑status checks.


All details are taken directly from the repository’s README; no additional features are inferred.

Related

  • Project
  • Project
  • Project
  • Project