Skip to content

feat: support vertex for claude code - #2573

Closed
Caisin wants to merge 4 commits into
QuantumNous:mainfrom
Caisin:main
Closed

Caisin wants to merge 4 commits into
QuantumNous:mainfrom
Caisin:main

Conversation

@Caisin

@Caisin Caisin commented Jan 4, 2026 •

Copy link
Copy Markdown
Contributor

修复: 以下错误

 channel error (channel #1, status code: 400): Invalid JSON payload received. Unknown name "anthropic_version": Cannot find field.
Invalid JSON payload received. Unknown name "max_tokens": Cannot find field.
Invalid JSON payload received. Unknown name "messages": Cannot find field.
Invalid JSON payload received. Unknown name "stream": Cannot find field.
Invalid JSON payload received. Unknown name "system": Cannot find field.
[ERR] 2026/01/04 - 14:36:51 | 20260104143650376792000GTypCvmJ | channel error (channel #1, status code: 400): Invalid JSON payload received. Unknown name "anthropic_version": Cannot find field.
Invalid JSON payload received. Unknown name "max_tokens": Cannot find field.
Invalid JSON payload received. Unknown name "messages": Cannot find field.
Invalid JSON payload received. Unknown name "stream": Cannot find field.
Invalid JSON payload received. Unknown name "system": Cannot find field.
[ERR] 2026/01/04 - 14:36:51 | 20260104143650376806000ZgXmO9XT | channel error (channel #1, status code: 400): Invalid JSON payload received. Unknown name "anthropic_version": Cannot find field.
Invalid JSON payload received. Unknown name "max_tokens": Cannot find field.
Invalid JSON payload received. Unknown name "messages": Cannot find field.
Invalid JSON payload received. Unknown name "description" at 'tools[0]': Ca
  1. 增加模式判断:通过 a.RequestMode(在 Init 方法中根据模型前缀确定)来区分当前请求的目标模型类型。
  2. 兼容非 Claude 模型:
    • 如果目标不是 Claude 模型(例如你配置了 gemini-1.5-pro 但通过 /v1/messages 接口调用)。
    • 代码会借用 openai.Adaptor 的转换能力,将 ClaudeRequest 转换为 GeneralOpenAIRequest。
    • 随后调用 a.ConvertOpenAIRequest。由于 ConvertOpenAIRequest 内部已经实现了将 OpenAI 格式转换为 Vertex Gemini/Llama 格式的逻辑,这样就完成了链路打通。
  3. 支持更多场景:这样修改后,你甚至可以通过 /v1/messages 接口来调用 Vertex 上的图片生成模型(imagen),因为它也会通过 OpenAI 格式中转并触发 ConvertImageRequest。

Summary by CodeRabbit

  • Chores

    • Removed several unused development and testing dependencies to reduce project bloat and simplify maintenance.
  • Refactor

    • Reworked internal request routing to improve multi-model handling, ensuring model-specific requests follow a clearer, more reliable conversion and forwarding flow.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 4, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Removed four test-related dependencies from go.mod. Updated relay/channel/vertex/adaptor.go ConvertClaudeRequest routing: Claude-mode requests are handled locally (vertex/Claude path) while non-Claude or other modes are delegated through the OpenAI adaptor and then forwarded to the OpenAI conversion path.

Changes

Cohort / File(s) Summary
Dependency Cleanup
go.mod
Removed four dependencies: github.com/stretchr/testify v1.11.1, github.com/davecgh/go-spew v1.1.1 (indirect), github.com/pmezard/go-difflib v1.0.0 (indirect), and github.com/stretchr/objx v0.5.2 (indirect).
Vertex adaptor routing
relay/channel/vertex/adaptor.go
Modified ConvertClaudeRequest control flow: when adaptor.RequestMode == RequestModeClaude it selects a Claude model via claudeModelMap(info.UpstreamModelName) (fallback to request.Model), builds and returns a vertex Claude request; otherwise it instantiates openai.Adaptor, delegates ConvertClaudeRequest to it, asserts the returned type to *dto.GeneralOpenAIRequest, and forwards the result to ConvertOpenAIRequest. Error handling added for adaptor creation and type assertion.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant VertexAdaptor as Vertex\nAdaptor (ConvertClaudeRequest)
    participant OpenAIAdaptor as OpenAI\nAdaptor
    participant OpenAIFlow as ConvertOpenAIRequest

    Client->>VertexAdaptor: Send Claude-origin request (info + request)
    alt RequestMode == RequestModeClaude
        VertexAdaptor->>VertexAdaptor: select model via claudeModelMap\ncopyRequest(...) -> vertexClaudeReq
        VertexAdaptor-->>Client: return vertexClaudeReq (vertex/Claude path)
    else Other modes / non-Claude-origin
        VertexAdaptor->>OpenAIAdaptor: ConvertClaudeRequest(generalize)
        OpenAIAdaptor-->>VertexAdaptor: *dto.GeneralOpenAIRequest
        VertexAdaptor->>OpenAIFlow: ConvertOpenAIRequest(general request)
        OpenAIFlow-->>Client: final OpenAI-handled request/response
    end
    Note over VertexAdaptor,OpenAIAdaptor: Errors on adaptor creation or type-assertion are returned
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • seefs001

Poem

🐰 I nibbled deps and cleared the stack,
Claude hops one path, others take the track.
If modes diverge, I point the way—
OpenAI lanes handle the rest of the play.
A little hop, a tidy patch today. 🥕

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 'feat: support vertex for claude code' directly aligns with the PR's main objective of adding Vertex support for Claude requests by implementing request-mode detection and routing logic.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 041eeec and f008fa5.

📒 Files selected for processing (1)
  • relay/channel/vertex/adaptor.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • relay/channel/vertex/adaptor.go

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b1f8b8 and 0933831.

📒 Files selected for processing (2)
  • go.mod
  • relay/channel/vertex/adaptor.go
💤 Files with no reviewable changes (1)
  • go.mod
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-05T17:14:17.246Z
Learnt from: neotf
Repo: QuantumNous/new-api PR: 1511
File: setting/ratio_setting/model_ratio.go:118-123
Timestamp: 2025-08-05T17:14:17.246Z
Learning: Claude models handle "-thinking" variants differently from Gemini models. For Claude models, only the base model (without "-thinking") gets an entry in defaultModelRatio map. The "-thinking" variants rely on the Claude relay handler stripping the suffix using strings.TrimSuffix(textRequest.Model, "-thinking") before looking up the ratio, so they automatically use the base model's ratio.

Applied to files:

  • relay/channel/vertex/adaptor.go
🔇 Additional comments (1)
relay/channel/vertex/adaptor.go (1)

93-108: LGTM! Multi-mode request routing via Claude endpoint is correctly implemented.

The branching logic properly handles non-Claude model routing: when RequestMode is not Claude, the code delegates to the OpenAI adaptor's ConvertClaudeRequest method and chains the result through ConvertOpenAIRequest, enabling Vertex Gemini and other models to use the /v1/messages endpoint.

The type assertion on line 108 is safe—openai.Adaptor.ConvertClaudeRequest returns the result of service.ClaudeToOpenAIRequest, which always produces a *dto.GeneralOpenAIRequest, and this type is preserved through the return chain.

Comment thread relay/channel/vertex/adaptor.go Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0933831 and 041eeec.

📒 Files selected for processing (1)
  • relay/channel/vertex/adaptor.go
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-05T17:14:17.246Z
Learnt from: neotf
Repo: QuantumNous/new-api PR: 1511
File: setting/ratio_setting/model_ratio.go:118-123
Timestamp: 2025-08-05T17:14:17.246Z
Learning: Claude models handle "-thinking" variants differently from Gemini models. For Claude models, only the base model (without "-thinking") gets an entry in defaultModelRatio map. The "-thinking" variants rely on the Claude relay handler stripping the suffix using strings.TrimSuffix(textRequest.Model, "-thinking") before looking up the ratio, so they automatically use the base model's ratio.

Applied to files:

  • relay/channel/vertex/adaptor.go
🧬 Code graph analysis (1)
relay/channel/vertex/adaptor.go (4)
relay/channel/openai/adaptor.go (1)
  • Adaptor (36-39)
relay/channel/adapter.go (1)
  • Adaptor (15-32)
relay/channel/claude/adaptor.go (1)
  • Adaptor (24-26)
dto/openai_request.go (1)
  • GeneralOpenAIRequest (28-102)
🔇 Additional comments (1)
relay/channel/vertex/adaptor.go (1)

93-101: LGTM! Claude mode routing is correct.

The short-circuit for Claude mode correctly maps the model, sets the context, and returns the Vertex-compatible Claude request. This aligns with the PR objective to handle Claude targets locally.

Comment thread relay/channel/vertex/adaptor.go Resolved
@seefs001

seefs001 commented Jan 4, 2026

Copy link
Copy Markdown
Collaborator

草你改代码怎么还删依赖的

@Caisin

Caisin commented Jan 4, 2026

Copy link
Copy Markdown
Contributor Author

草你改代码怎么还删依赖的

估计本地运行时候执行了下 go mod tidy 自动修改了,我还原下

@Caisin

Caisin commented Jan 4, 2026

Copy link
Copy Markdown
Contributor Author

响应还是有问题
不能兼容

@Caisin Caisin closed this Jan 4, 2026
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