claude-code-api  by codingworkflow

API gateway for Claude models with OpenAI compatibility

Created 8 months ago
263 stars

Top 96.9% on SourcePulse

GitHubView on GitHub
Project Summary

Provides an OpenAI-compatible API gateway for the Claude Code CLI, enabling developers to integrate Claude models into existing applications and workflows designed for OpenAI APIs. This project targets developers seeking to leverage Claude's capabilities through a familiar API interface, offering a seamless transition and enhanced flexibility.

How It Works

This project acts as a middleware layer, exposing standard OpenAI API endpoints such as /v1/chat/completions and /v1/models. It routes incoming requests to the underlying Claude Code CLI, translating them into a format the CLI understands. Key features include support for both streaming and non-streaming chat completions, alongside a flexible model aliasing and fallback mechanism to ensure robustness when specific model versions are unavailable.

Quick Start & Requirements

  • Linux/macOS:
    git clone https://github.com/codingworkflow/claude-code-api
    cd claude-code-api
    make install
    make start
    
  • Windows: Utilize provided wrappers: make.bat install and start.bat. Note that Claude Code CLI support on Windows may require WSL.
  • Prerequisites: Claude Code CLI must be installed and configured.
  • Server URLs: API: http://localhost:8000, OpenAPI docs: http://localhost:8000/docs, Health: http://localhost:8000/health.
  • Configuration: Core settings like claude_binary_path and database_url are in claude_code_api/core/config.py. Model configurations can be managed in claude_code_api/config/models.json or via the CLAUDE_CODE_API_MODELS_PATH environment variable.

Highlighted Details

  • Offers OpenAI-style endpoints, including /v1/chat/completions, /v1/models, and session/project APIs.
  • Supports both streaming and non-streaming chat completion responses.
  • Implements model aliasing (e.g., opus, claude-opus-latest) and fallback behavior, retrying with alternative configured models if the primary choice fails.
  • The model field in requests is optional; if omitted, the Claude Code CLI's default model is used.
  • Supported models include specific versions of Opus, Sonnet, and Haiku.

Maintenance & Community

Bug reports and support are managed through a discussion thread linked to the ai-code-fusion repository: https://github.com/codingworkflow/ai-code-fusion/discussions/151. Developer-specific documentation is available at docs/dev.md.

Licensing & Compatibility

This project is licensed under the GNU General Public License v3.0 (GPL-3.0). This is a strong copyleft license, which may impose restrictions on linking with proprietary or closed-source software, requiring careful consideration for commercial adoption.

Limitations & Caveats

The project's functionality is dependent on the correct installation and configuration of the Claude Code CLI. Windows users may require the Windows Subsystem for Linux (WSL) for full compatibility. The GPL-3.0 license necessitates careful review for any integration into commercial or closed-source products.

Health Check
Last Commit

1 week ago

Responsiveness

Inactive

Pull Requests (30d)
24
Issues (30d)
0
Star History
26 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.