claude-code-openai-wrapper  by RichardAtCT

OpenAI-compatible API wrapper for Claude Code

Created 6 months ago
339 stars

Top 81.4% on SourcePulse

GitHubView on GitHub
Project Summary

This project provides an OpenAI API-compatible wrapper for Anthropic's Claude Code models, enabling developers to integrate Claude's capabilities into existing applications and workflows that rely on OpenAI's client libraries. It targets developers, researchers, and power users seeking to leverage advanced Claude models through a familiar API interface, offering benefits such as seamless integration, real-time cost tracking, and enhanced session management.

How It Works

The wrapper functions as a FastAPI server that translates incoming OpenAI API requests into calls directed at the Claude Code CLI, utilizing the official Claude Agent SDK (v0.1.6). It intelligently handles authentication across multiple providers (API key, Bedrock, Vertex AI, CLI), validates and selects Claude models, processes system prompts, and supports both streaming and non-streaming responses. By default, it disables tools for performance, mirroring OpenAI's default behavior, but allows optional tool enablement for specific tasks like file I/O or bash commands.

Quick Start & Requirements

  • Primary install/run:
    1. Install Claude Code CLI: npm install -g @anthropic-ai/claude-code
    2. Clone repository: git clone https://github.com/RichardAtCT/claude-code-openai-wrapper
    3. Navigate and install dependencies: cd claude-code-openai-wrapper && poetry install
    4. Start server: poetry run uvicorn src.main:app --reload --port 8000
  • Prerequisites: Claude Code CLI 2.0.0+, Node.js, Python 3.10+, Poetry, and a chosen authentication method (CLI, API key, AWS Bedrock, or Google Vertex AI).
  • Links: GitHub Repository

Highlighted Details

  • Full OpenAI /v1/chat/completions endpoint compatibility.
  • Integration with the official Claude Agent SDK v0.1.6.
  • Multi-provider authentication support (CLI, API Key, AWS Bedrock, Google Vertex AI).
  • Session continuity via session_id for maintaining conversation history.
  • Real-time cost and token tracking derived directly from SDK metadata.
  • Fast default mode with tools disabled; optional tool usage (Read, Write, Bash).
  • API security features including interactive key protection and rate limiting.

Maintenance & Community

The project has recently undergone a major update (v2.0.0) migrating to the Claude Agent SDK, indicating active development. No specific community channels (like Discord or Slack) or notable contributors/sponsorships are detailed in the README.

Licensing & Compatibility

The project is released under the MIT License, permitting commercial use and modification with attribution. It is designed for compatibility with all standard OpenAI client libraries.

Limitations & Caveats

Function calling is not directly supported, with tools being enabled via prompt-based configurations. Several OpenAI parameters like temperature, top_p, and max_tokens are not yet mapped. The wrapper also does not support generating multiple responses (n > 1) per request, and images within messages are converted to text placeholders.

Health Check
Last Commit

5 days ago

Responsiveness

Inactive

Pull Requests (30d)
4
Issues (30d)
3
Star History
92 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.