Skip to content

fix: fetch upstream models - #2394

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/fetch-model-header-overide
Dec 9, 2025
Merged

fix: fetch upstream models#2394
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/fetch-model-header-overide

Conversation

@seefs001

@seefs001 seefs001 commented Dec 8, 2025

Copy link
Copy Markdown
Collaborator

fix #2389

Summary by CodeRabbit

  • Refactor
    • Improved request header computation logic for upstream model fetching operations, enhancing maintainability and error handling consistency.

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

@coderabbitai

coderabbitai Bot commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A new helper function buildFetchModelsHeaders is added to controller/channel.go to consolidate header computation logic for the FetchUpstreamModels operation. This function applies channel-type-specific headers and header overrides, ensuring header override configurations are properly applied to upstream model fetch requests.

Changes

Cohort / File(s) Summary
Header Processing Helper
controller/channel.go
Added buildFetchModelsHeaders(channel *model.Channel, key string) function to compute request headers based on channel type and header overrides; integrated into FetchUpstreamModels to replace inline header logic and enable header override application.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify the new buildFetchModelsHeaders function correctly prioritizes and merges channel-type-specific headers with header override configurations
  • Confirm proper error handling and propagation within the function
  • Validate integration with FetchUpstreamModels and GetResponseBody call sites

Possibly related PRs

Poem

🐰 A header helper hops to the rescue,
Cloudflare's auth now flows through the channel,
Overrides cascade like morning dew,
No more silent failures to unravels—
Requests rise with proper care! ✨

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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: fetch upstream models' is concise and clearly relates to the main change in the pull request, which addresses the FetchUpstreamModels function to apply request header overrides.
Linked Issues check ✅ Passed The pull request adds the buildFetchModelsHeaders function to apply request header overrides in FetchUpstreamModels, directly addressing issue #2389's requirement to support custom headers like cf-aig-authorization.
Out of Scope Changes check ✅ Passed All changes focus on the FetchUpstreamModels functionality and header handling, which are directly aligned with the linked issue #2389 objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ebc713 and c7539d1.

📒 Files selected for processing (1)
  • controller/channel.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
controller/channel.go (3)
model/channel.go (1)
  • Channel (21-58)
constant/channel.go (1)
  • ChannelTypeAnthropic (18-18)
controller/channel-billing.go (3)
  • GetClaudeAuthHeader (132-137)
  • GetAuthHeader (125-129)
  • GetResponseBody (139-167)
🔇 Additional comments (2)
controller/channel.go (2)

168-190: Excellent implementation that solves the header override issue.

The function correctly:

  • Applies channel-type-specific headers (Anthropic vs. default Bearer token)
  • Iterates through header overrides and validates that values are strings
  • Replaces {api_key} placeholders dynamically
  • Returns clear error messages for invalid configurations

The use of headers.Set() properly implements override semantics, ensuring custom headers like cf-aig-authorization will be applied when fetching upstream models.


250-256: Correct integration that fixes the missing header override application.

The refactored code properly builds headers with overrides applied before making the upstream request. This directly addresses issue #2389.

However, manual verification is required to confirm:

  • The buildFetchModelsHeaders function correctly applies header overrides
  • The GetResponseBody call properly utilizes the constructed headers
  • The error handling flow matches the intended behavior

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 4ffd54c into QuantumNous:main Dec 9, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 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.

GET /fetch_models/:id 接口未应用请求头覆盖配置

2 participants