feat: add Claude API compatible endpoint (/v1/messages)#56
feat: add Claude API compatible endpoint (/v1/messages)#56bbbugg merged 1 commit intoiBUHub:mainfrom
Conversation
Add support for Claude/Anthropic API format, allowing clients using
Anthropic SDK to connect directly.
Features:
- New endpoint: POST /v1/messages
- Claude to Gemini request format conversion
- Gemini to Claude response format conversion (stream & non-stream)
- Support for system prompt (separate 'system' field)
- Support for tool_use and tool_result
- Support for thinking blocks
- Proper SSE event format (message_start, content_block_delta, etc.)
Usage:
```python
import anthropic
client = anthropic.Anthropic(
api_key="your-key",
base_url="http://localhost:7860"
)
message = client.messages.create(
model="gemini-2.5-flash",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
```
There was a problem hiding this comment.
Pull request overview
This PR adds Claude/Anthropic API compatibility to the Gemini proxy, enabling clients using Anthropic's SDK to connect to Gemini models through a Claude-compatible interface at /v1/messages.
Changes:
- New Claude API endpoint with bidirectional format conversion between Claude and Gemini formats
- Support for streaming and non-streaming modes with proper SSE event formatting
- Handling of Claude-specific features including system prompts, tool use/results, and thinking blocks
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 13 comments.
| File | Description |
|---|---|
| src/core/ProxyServerSystem.js | Adds POST route for /v1/messages endpoint |
| src/core/RequestHandler.js | Implements processClaudeRequest handler with streaming/non-streaming support and Claude-specific error formatting |
| src/core/FormatConverter.js | Adds bidirectional conversion methods: translateClaudeToGoogle, translateGoogleToClaudeStream, and convertGoogleToClaudeNonStream |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
claude 开启思考应该直接判断顶层的 |
|
已根据 review 反馈进行修复,提交 4c399b5: 已修复的问题
待讨论
|
|
辛苦了大佬。Copilot review我们来改就行,他很多说的不对。修正的只有思考模式判断就可以了。 |
Summary
This PR adds support for Claude/Anthropic API format, allowing clients using Anthropic SDK to connect directly to this proxy.
New Features
POST /v1/messagessystemfieldtool_useandtool_resultblocksmessage_start,content_block_delta,message_stop, etc.)Usage Example
Files Changed
src/core/FormatConverter.js- Added Claude ↔ Gemini conversion methodssrc/core/RequestHandler.js- AddedprocessClaudeRequest()handlersrc/core/ProxyServerSystem.js- Added/v1/messagesrouteTesting
All tests passed: