Skip to content

Claude cache - #2949

Closed
funkpopo wants to merge 9 commits into
QuantumNous:mainfrom
funkpopo:claude-cache
Closed

Claude cache#2949
funkpopo wants to merge 9 commits into
QuantumNous:mainfrom
funkpopo:claude-cache

Conversation

@funkpopo

@funkpopo funkpopo commented Feb 14, 2026

Copy link
Copy Markdown
Contributor

@seefs001
能帮我审查一下这次改动吗?对于Claude的缓存我不太熟悉,想学习一下。非常感谢!

作为new-api而不是商业中转,我的改动是否符合new-api的需求?

Summary by CodeRabbit

  • New Features
    • Introduced prompt caching optimization for Claude requests to improve performance and reduce latency.
    • Added automatic user metadata injection to support enhanced routing and session consistency.
    • Added configuration options to enable or disable automatic cache control and metadata injection features.

@funkpopo funkpopo closed this Feb 14, 2026
@coderabbitai

coderabbitai Bot commented Feb 14, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request adds prompt caching optimization and metadata injection to Claude API requests. It introduces two helper functions (injectSystemCacheControl and injectMetadataUserId) for conditionally applying ephemeral cache control and user metadata to requests, integrates them into the request construction pipeline, and adds two new configuration flags to control this behavior.

Changes

Cohort / File(s) Summary
Claude Request Processing
relay/channel/claude/relay-claude.go, relay/channel/claude/adaptor.go
Introduces injectSystemCacheControl and injectMetadataUserId helper functions to conditionally append ephemeral cache control and attach user metadata (token_id) to Claude requests. Integrates helpers into request conversion flow; note that injectMetadataUserId is called twice in the flow (potential duplication).
Claude Configuration
setting/model_setting/claude.go
Adds two new boolean configuration fields (AutoInjectCacheControl and AutoInjectMetadataUserId) to control automatic injection of cache control and user metadata, with documentation explaining their purpose for prompt caching and sticky routing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • seefs001
  • Calcium-Ion

Poem

🐰 Whiskers twitched with cache delight,
System prompts now gleam so bright,
Metadata flows through tunnels deep,
Ephemeral guards our secrets keep!
Relay hops with joy and care,
Optimization floats through air ✨

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

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

@funkpopo
funkpopo deleted the claude-cache branch February 14, 2026 02:13
@funkpopo
funkpopo restored the claude-cache branch February 14, 2026 02:14
@funkpopo
funkpopo deleted the claude-cache branch July 13, 2026 00:41
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.

1 participant