feat: support claude cache and thinking for upstream [OpenRouter] - #983
Merged
Conversation
There was a problem hiding this comment.
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"`
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
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.