Skip to content

feat: use proxy HTTP client fetch models - #1584

Merged
Calcium-Ion merged 1 commit into
QuantumNous:alphafrom
feitianbubu:pr/use-proxy-fetch-models
Aug 16, 2025
Merged

Calcium-Ion merged 1 commit into
QuantumNous:alphafrom
feitianbubu:pr/use-proxy-fetch-models

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Aug 13, 2025 •

Copy link
Copy Markdown
Member

支持渠道获取模型时使用代理
2025 08 13_傅兴敏 5dfc4eb2908bebbbceec897703cba46e

Summary by CodeRabbit

  • New Features
    • Added per-channel proxy settings for outbound requests, enabling each channel to use its own proxy.
    • Improves connectivity and reliability across diverse network environments.
    • Existing setups continue to work without changes; if no proxy is set for a channel, behavior remains unchanged.

@coderabbitai

coderabbitai Bot commented Aug 13, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Updated GetResponseBody in controller/channel-billing.go to build and use a channel-specific proxy HTTP client based on channel settings. If proxy client creation fails, it returns an error; otherwise, it performs the request via the constructed client. Response handling logic remains the same.

Changes

Cohort / File(s) Summary
Channel billing proxy usage
controller/channel-billing.go
Refactored GetResponseBody to instantiate a proxy-aware HTTP client per channel using channel.GetSetting().Proxy; uses client.Do(req) and returns error on client creation failure; retained existing error handling and response processing.

Sequence Diagram(s)

sequenceDiagram
  participant C as Caller
  participant B as GetResponseBody
  participant F as ProxyClientFactory
  participant H as HTTP Client
  participant U as Upstream Service

  C->>B: GetResponseBody(req, channel)
  B->>F: Create client with channel.GetSetting().Proxy
  alt Client creation fails
    F-->>B: Error
    B-->>C: Return error
  else Success
    F-->>B: Proxy HTTP client
    B->>H: client.Do(req)
    H->>U: HTTP request (via proxy if set)
    U-->>H: HTTP response
    H-->>B: Response
    B-->>C: Processed response
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A whisk of wire, a hop of byte,
I route each call through proxy light.
Per-channel paths, precisely spun,
Carrots aligned, requests now run.
With twitching ears I test and see—
One tunnel per burrow, latency-free! 🥕🚀

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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: 0

🧹 Nitpick comments (1)
controller/channel-billing.go (1)

138-142: Consider fallback behavior when proxy creation fails.

While the current implementation correctly returns an error when proxy client creation fails, consider whether a fallback to a default HTTP client would be more appropriate for better availability, especially if proxy configuration is optional.

If proxy usage should be optional and fall back to default behavior when proxy setup fails, consider this approach:

-	client, err := service.NewProxyHttpClient(channel.GetSetting().Proxy)
-	if err != nil {
-		return nil, err
-	}
+	client, err := service.NewProxyHttpClient(channel.GetSetting().Proxy)
+	if err != nil {
+		// Log the proxy setup failure and fallback to default client
+		common.SysLog(fmt.Sprintf("Failed to create proxy client for channel %d: %v, using default client", channel.Id, err))
+		client = &http.Client{Timeout: 30 * time.Second}
+	}

However, if proxy usage is mandatory when configured, the current error-returning approach is correct.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 196e2a0 and 01cd279.

📒 Files selected for processing (1)
  • controller/channel-billing.go (1 hunks)
🔇 Additional comments (1)
controller/channel-billing.go (1)

138-142: Verified service.NewProxyHttpClient implementation and error handling

The NewProxyHttpClient function is defined in service/http_client.go:32 and correctly handles all supported proxy scenarios:

  • Returns http.DefaultClient when proxyURL is empty.
  • Parses the provided URL and returns an error on parse failure.
  • Supports “http”/“https” schemes via http.Transport{ Proxy: http.ProxyURL(...) }.
  • Supports “socks5”/“socks5h” schemes with a SOCKS5 dialer (including optional authentication).
  • Returns a clear error for any unsupported proxy scheme.

No changes are required here.

@Calcium-Ion
Calcium-Ion merged commit 0ad918c into QuantumNous:alpha Aug 16, 2025
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
…ch-models

feat: use proxy HTTP client fetch models
@coderabbitai coderabbitai Bot mentioned this pull request Jul 18, 2026
8 of 11 tasks
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…ch-models

feat: use proxy HTTP client fetch models
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…ch-models

feat: use proxy HTTP client fetch models
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