Skip to content

Build API proxy for cloud service access#2

Open
milhy545 wants to merge 2 commits intomasterfrom
claude/api-proxy-subscription-01H41a3evgHRaCTuVjH1fbkX
Open

Build API proxy for cloud service access#2
milhy545 wants to merge 2 commits intomasterfrom
claude/api-proxy-subscription-01H41a3evgHRaCTuVjH1fbkX

Conversation

@milhy545
Copy link
Owner

No description provided.

This major update adds a production-ready API proxy server that converts
Claude subscription access into an OpenAI-compatible REST API, enabling
cost-effective Claude usage for developers.

Features:
- OpenAI-compatible /v1/chat/completions endpoint
- Full streaming support via Server-Sent Events (SSE)
- Request/response format converters (OpenAI ↔ Claude)
- Health check and model listing endpoints
- FastAPI-based async architecture
- Comprehensive error handling and logging
- Session management and cost tracking
- CLI tool (claude-api-proxy) for easy server startup

Use cases:
- Use Claude subscription instead of expensive API access
- Enable remote Claude Code access via API
- Integrate with LangChain, OpenAI client, and other frameworks
- Cost savings for heavy Claude users ($20/month vs per-token API pricing)

Technical details:
- Added FastAPI, uvicorn, and sse-starlette dependencies
- Created ClaudeAPIProxy class with streaming support
- Implemented FormatConverter for OpenAI/Claude format translation
- Added comprehensive documentation (API_PROXY.md)
- Included usage examples and integration guides
- Full test suite with syntax validation

Documentation:
- API_PROXY.md: Complete API proxy documentation
- examples/api_proxy_usage.py: Usage examples for various integrations
- Updated README.md with API proxy quick start guide
- Includes curl, Python, LangChain, and Claude Code examples

This implementation enables developers to leverage their Claude subscription
for API-based access, potentially saving thousands of dollars while maintaining
full OpenAI compatibility for existing tools and frameworks.
Ignore Python cache files, build artifacts, virtual environments,
and IDE/OS-specific files to keep the repository clean.
@gemini-code-assist
Copy link

Summary of Changes

Hello @milhy545, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a powerful new feature: an OpenAI-compatible API proxy for Claude. The primary goal is to empower users with Claude subscriptions to access Claude models through a standard REST API, bypassing expensive API keys and seamlessly integrating with a broader ecosystem of AI development tools. This enhancement provides a flexible and cost-effective way to interact with Claude, complete with streaming capabilities and robust documentation.

Highlights

  • New OpenAI-Compatible API Proxy: Introduced a new API proxy that converts a Claude subscription into an OpenAI-compatible REST API, allowing users to leverage their subscription for tools and frameworks expecting an OpenAI interface without incurring additional API costs.
  • Cost Savings and Integration: The proxy enables significant cost savings by utilizing subscription pricing and facilitates integration with popular AI tools like OpenAI Python client, LangChain, and Claude Code, which can now connect to Claude via this compatible API.
  • Streaming and Non-Streaming Support: The API proxy supports both streaming (Server-Sent Events) and non-streaming chat completions, providing flexibility for various application needs.
  • Comprehensive Documentation and Examples: Detailed documentation (API_PROXY.md) has been added, covering quick start guides, usage examples, API endpoints, security considerations, configuration, monitoring, troubleshooting, and advanced use cases like programmatic access and running as a service.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@milhy545
Copy link
Owner Author

@gemini-code-assist

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant new feature: an OpenAI-compatible API proxy that allows using a Claude subscription. This is a great addition. The implementation is comprehensive, including documentation, examples, and the core proxy server logic using FastAPI. However, I've identified a critical security vulnerability in the Docker documentation that needs immediate attention. Additionally, there are several high and medium severity issues related to application design, correctness, and maintainability that should be addressed to make the feature robust and secure. My detailed comments are below.

@gemini-code-assist
Copy link

@milhy545, thanks for reaching out! Do you have any specific questions about the summary or the changes in this pull request? Or would you like me to proceed with a detailed code review? Feel free to ask, or use /gemini review for a full review.

Copy link
Owner Author

@milhy545 milhy545 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/gemini review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants