Skip to content

feat: support claude cache and thinking for upstream [OpenRouter] - #983

Merged
creamlike1024 merged 6 commits into
QuantumNous:mainfrom
neotf:feat-02
Jun 5, 2025
Merged

feat: support claude cache and thinking for upstream [OpenRouter]#983
creamlike1024 merged 6 commits into
QuantumNous:mainfrom
neotf:feat-02

Conversation

@neotf

@neotf neotf commented Apr 18, 2025

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for processing Claude's cache and thinking parameters to work with the OpenRouter upstream. The changes include updating the conversion logic for Claude requests, introducing new OpenRouter DTOs, and propagating cache control metadata in media messages.

  • Adjusted thinking and reasoning handling in ClaudeToOpenAIRequest based on the channel type.
  • Introduced RequestReasoning struct in the openrouter package.
  • Updated DTOs to include Reasoning and CacheControl fields.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
service/convert.go Updated thinking handling and system message processing for OpenRouter logic
relay/channel/openrouter/dto.go Added DTO for reasoning parameters
dto/openai_request.go Added Reasoning and CacheControl fields for OpenRouter integration
dto/claude.go Propagated CacheControl field in Claude media message DTO
Comments suppressed due to low confidence (5)

service/convert.go:83

  • [nitpick] Consider parameterizing the hardcoded 'anthropic/claude' prefix to improve future maintainability in case model naming conventions change.
isOpenRouterClaude := isOpenRouter && strings.HasPrefix(info.UpstreamModelName, "anthropic/claude")

service/convert.go:131

  • [nitpick] Ensure that mediaMsg.CacheControl reliably contains a valid JSON representation that downstream services expect.
CacheControl: mediaMsg.CacheControl,

dto/openai_request.go:58

  • Verify that adding the Reasoning field does not conflict with existing request processing and that consumers can handle its presence appropriately.
Reasoning json.RawMessage `json:"reasoning,omitempty"`

dto/openai_request.go:122

  • [nitpick] Consider adding inline documentation to clarify the expected format and usage of the CacheControl field.
CacheControl json.RawMessage `json:"cache_control,omitempty"`

dto/claude.go:21

  • [nitpick] Add a comment to describe the intended content and purpose of the CacheControl field in this DTO.
CacheControl json.RawMessage      `json:"cache_control,omitempty"`

@creamlike1024
creamlike1024 merged commit 3665ad6 into QuantumNous:main Jun 5, 2025
@neotf
neotf deleted the feat-02 branch June 5, 2025 10:22
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
…antumNous#983)

* feat: support claude cache for upstream [OpenRouter]

* feat: support claude thinking for upstream [OpenRouter]

* feat: reasoning is common params for OpenRouter
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.

3 participants