Skip to content

fix: 使用openai兼容接口调用部分渠道在最终端点为claude原生端点下还是走了openai扣减input_token的逻辑 - #2883

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/claude-relay-info-input-token
Feb 7, 2026
Merged

fix: 使用openai兼容接口调用部分渠道在最终端点为claude原生端点下还是走了openai扣减input_token的逻辑#2883
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/claude-relay-info-input-token

Conversation

@seefs001

@seefs001 seefs001 commented Feb 7, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Improved error messages with specific endpoint references for unsupported operations in Codex integration.
  • Refactor

    • Centralized Claude response handling across multiple channel adapters through a unified adaptor pattern for better code maintainability.

@coderabbitai

coderabbitai Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR centralizes Claude response handling across multiple relay channel adaptors by delegating to a unified claude.Adaptor.DoResponse() method instead of inline handler branches. It introduces a new FinalRequestRelayFormat field to RelayInfo for tracking the final upstream relay format, updates error messages in the Codex adaptor with endpoint-specific references, and refactors Claude-detection logic to use the new field.

Changes

Cohort / File(s) Summary
Claude Adaptor Pattern Unification
relay/channel/ali/adaptor.go, relay/channel/deepseek/adaptor.go, relay/channel/moonshot/adaptor.go, relay/channel/vertex/adaptor.go, relay/channel/volcengine/adaptor.go, relay/channel/zhipu_4v/adaptor.go
Replace inline Claude response handling (direct calls to ClaudeStreamHandler and ClaudeHandler based on info.IsStream) with delegation to claude.Adaptor{}.DoResponse().
Claude Adaptor Setup
relay/channel/claude/adaptor.go
Set info.FinalRequestRelayFormat to types.RelayFormatClaude before branching on stream status.
Codex Endpoint Messages
relay/channel/codex/adaptor.go
Replace generic error messages with endpoint-specific references: /v1/messages, /v1/chat/completions, /v1/rerank, /v1/embeddings.
RelayInfo Enhancement
relay/common/relay_info.go
Add public field FinalRequestRelayFormat of type types.RelayFormat to track final upstream relay format for Claude.
Claude Detection Refactoring
relay/compatible_handler.go
Replace ChannelTypeAnthropic condition with FinalRequestRelayFormat == RelayFormatClaude for Claude usage semantic detection.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • Calcium-Ion

Poem

🐰 Six channels unified in harmony,
Claude's responses flow through adaptor's decree,
A format field marks the final way,
Endpoints speak their names today,
Pattern, clean and structured we see! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is in Chinese and describes a bug fix related to Claude relay format handling and token deduction logic, which aligns with the core changes across multiple adaptor files to delegate Claude response handling to claude.Adaptor and track FinalRequestRelayFormat.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 742f4ad into QuantumNous:main Feb 7, 2026
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…fo-input-token

fix: 使用openai兼容接口调用部分渠道在最终端点为claude原生端点下还是走了openai扣减input_token的逻辑
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