Skip to content

feat: /v1/messages -> /v1/responses - #2889

Merged
Calcium-Ion merged 3 commits into
QuantumNous:mainfrom
seefs001:feature/messages2responses
Feb 7, 2026
Merged

feat: /v1/messages -> /v1/responses#2889
Calcium-Ion merged 3 commits into
QuantumNous:mainfrom
seefs001:feature/messages2responses

Conversation

@seefs001

@seefs001 seefs001 commented Feb 7, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved API endpoint routing and request handling for multi-model compatibility.
    • Enhanced response formatting and streaming across different AI model formats.
    • Optimized request conversion and error handling for better reliability.

@coderabbitai

coderabbitai Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

These changes introduce an alternative request routing path for Claude format requests, enabling them to be converted to OpenAI format and processed through a responses-based adaptor. URL resolution and response marshaling are adjusted to support Claude-to-OpenAI conversion and format-aware response handling.

Changes

Cohort / File(s) Summary
URL Routing Logic
relay/channel/openai/adaptor.go
Modified GetRequestURL default case to restrict /v1/chat/completions endpoint for Claude/Gemini formats when RelayMode is Responses or ResponsesCompact, falling back to standard URL path instead.
Response Formatting & Streaming
relay/channel/openai/chat_via_responses.go
Refactored response handling to format JSON body based on RelayFormat (using Claude/Gemini wrappers or default). Introduced sendChatChunk helper to abstract streaming chunk transmission with format-specific marshaling. Added Claude-specific usage propagation and conditional helper.Done finalization for OpenAI format only.
Claude Request Handler
relay/claude_handler.go
Added early-exit path that converts Claude requests to OpenAI format via ClaudeToOpenAIRequest, processes them through chatCompletionsViaResponses, posts usage quota, and returns immediately when pass-through is disabled and responses-based processing is configured.

Sequence Diagram

sequenceDiagram
    participant Client
    participant ClaudeHandler as Claude Handler
    participant Adaptor as OpenAI Adaptor
    participant ResponseFormatter as Response Formatter
    participant Backend as OpenAI Backend

    Client->>ClaudeHandler: Claude Request
    activate ClaudeHandler
    
    alt Pass-through disabled & Responses mode enabled
        ClaudeHandler->>ClaudeHandler: Convert Claude → OpenAI
        ClaudeHandler->>Adaptor: Resolve Request URL
        Adaptor-->>ClaudeHandler: URL (based on RelayMode)
        ClaudeHandler->>Backend: Forward OpenAI Request
        Backend-->>ClaudeHandler: OpenAI Response Stream
        
        ClaudeHandler->>ResponseFormatter: Format Response
        activate ResponseFormatter
        ResponseFormatter->>ResponseFormatter: Check RelayFormat (Claude/Gemini/OpenAI)
        ResponseFormatter->>ResponseFormatter: sendChatChunk (with format wrapper)
        ResponseFormatter-->>ClaudeHandler: Formatted Stream
        deactivate ResponseFormatter
        
        ClaudeHandler->>ClaudeHandler: Post Usage Quota
        ClaudeHandler-->>Client: Claude Format Response
    else
        ClaudeHandler->>Backend: Standard Claude Flow
        Backend-->>Client: Response
    end
    deactivate ClaudeHandler
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #2837: Modifies chat_via_responses.go to refactor reasoning-summary and reasoning-stream handling in chat-completion deltas, directly related to the streaming refactor in this PR.
  • PR #2296: Changes Claude request/response routing to use OpenAI adaptor path, aligning with the early-exit routing mechanism introduced here.
  • PR #1531: Modifies ClaudeToOpenAIRequest conversion logic that is directly invoked by the new early-exit branch in claude_handler.go.

Suggested reviewers

  • Calcium-Ion
  • creamlike1024

Poem

🐰 A Claude hops through OpenAI's door,
With format conversions galore,
Via responses it streams so swift,
Each chunk finds its proper drift,
No longer bound by native shore! ✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Calcium-Ion
Calcium-Ion merged commit 8979552 into QuantumNous:main Feb 7, 2026
1 check was pending
@seefs001 seefs001 linked an issue Feb 7, 2026 that may be closed by this pull request
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…sponses

feat: /v1/messages -> /v1/responses
@coderabbitai coderabbitai Bot mentioned this pull request May 12, 2026
10 tasks
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.

message <=> respones

2 participants