Skip to content

Conversation

creamlike1024
Copy link
Collaborator

@creamlike1024 creamlike1024 commented Aug 10, 2025

更新 web search tool 价格,适配 gpt-5
https://platform.openai.com/docs/pricing?latest-pricing=standard#built-in-tools

Summary by CodeRabbit

  • Bug Fixes
    • Updated pricing rules for web search models to reflect correct rates for gpt-5, "o" series, gpt-4o, and gpt-4.1 models.
    • Adjusted model classification to ensure accurate pricing based on model name.

Copy link
Contributor

coderabbitai bot commented Aug 10, 2025

Walkthrough

The change updates the pricing logic and accompanying comments for web search models within a single file. The condition for assigning models to different price tiers was revised, specifically changing which model names are matched for the lower price tier. No changes were made to function signatures or public interfaces.

Changes

Cohort / File(s) Change Summary
Web Search Pricing Logic Update
setting/operation_setting/tools.go
Updated comments to clarify model pricing rules; modified internal logic to use "gpt-5" prefix instead of "deep-research" for determining price tier. No API or signature changes.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant ToolsGo

    Caller->>ToolsGo: GetWebSearchPricePerThousand(modelName, contextSize)
    alt modelName starts with "gpt-5" or is "o" series
        ToolsGo-->>Caller: Return $10.00 per 1K calls (extra tokens counted)
    else modelName is "gpt-4o" or "gpt-4.1" series
        ToolsGo-->>Caller: Return $25.00 per 1K calls (no extra tokens)
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Poem

In the warren where the price tags grow,
Rabbits ponder models, high and low.
"gpt-5" hops in for a cheaper fare,
While "gpt-4o" pays more—life’s never fair!
With carrots counted, logic neat,
This update makes our pricing sweet. 🥕

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch update-openai-websearch-price

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
  • 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 src/utils.ts and explain its main purpose.
    • @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 comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
setting/operation_setting/tools.go (1)

31-34: contextSize parameter is now dead code

The comment says pricing no longer depends on context size, yet contextSize remains in the signature and is never used.
Removing it (or marking as deprecated) will prevent confusion for future callers.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1cc81de and 6cf84b1.

📒 Files selected for processing (1)
  • setting/operation_setting/tools.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-21T03:37:41.726Z
Learnt from: 9Ninety
PR: QuantumNous/new-api#1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.

Applied to files:

  • setting/operation_setting/tools.go

Comment on lines 38 to +40
strings.HasPrefix(modelName, "o3") ||
strings.HasPrefix(modelName, "o4") ||
strings.Contains(modelName, "deep-research")
strings.HasPrefix(modelName, "gpt-5")
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Model-prefix check may miss future “o” versions

Only o3 and o4 prefixes are treated as the low-tier models.
If OpenAI releases o5 (or any other o*) the code will silently charge the higher price.
Consider matching the whole family, e.g.:

isNormalPriceModel :=
    strings.HasPrefix(modelName, "o") ||
    strings.HasPrefix(modelName, "gpt-5")

or keep an allow-list constant that is easier to extend.


🏁 Script executed:

#!/bin/bash
set -e
# Locate the tools.go file under operation_setting
file=$(fd "tools.go" | grep "setting/operation_setting/tools.go" | head -n 1)
echo "Found file: $file"

# Print the first 200 lines to inspect the function definition and usage
echo -e "\n--- File content (lines 1–200) ---"
sed -n '1,200p' "$file"

# Search for contextSize occurrences in the file
echo -e "\n--- contextSize occurrences ---"
grep -n "contextSize" "$file" || echo "No occurrences of contextSize found"

Length of output: 2693


Update model-prefix logic and remove unused contextSize parameter

  • Remove the unused contextSize parameter from GetWebSearchPricePerThousand (both signature and all call sites).
  • Broaden the “o”-series match so future variants (e.g. o5) fall under the normal-price tier.
  • Example diff:
--- a/setting/operation_setting/tools.go
+++ b/setting/operation_setting/tools.go
@@ -28,7 +28,7 @@
- func GetWebSearchPricePerThousand(modelName string, contextSize string) float64 {
+ func GetWebSearchPricePerThousand(modelName string) float64 {
     // …pricing comments…
-    isNormalPriceModel :=
-        strings.HasPrefix(modelName, "o3") ||
-            strings.HasPrefix(modelName, "o4") ||
-            strings.HasPrefix(modelName, "gpt-5")
+    isNormalPriceModel :=
+        strings.HasPrefix(modelName, "o") ||
+        strings.HasPrefix(modelName, "gpt-5")
     var priceWebSearchPerThousandCalls float64
     if isNormalPriceModel {
         priceWebSearchPerThousandCalls = WebSearchPrice

By matching "o" you ensure any future o-series models use the correct rate.

🤖 Prompt for AI Agents
In setting/operation_setting/tools.go around lines 38 to 40, remove the unused
contextSize parameter from the GetWebSearchPricePerThousand function signature
and all its call sites. Update the model prefix matching logic by replacing the
specific "o3" and "o4" prefixes with a broader check for any model starting with
"o" to include future variants like "o5" under the normal-price tier. Adjust the
strings.HasPrefix conditions accordingly to match "o" instead of specific
versions.

@creamlike1024 creamlike1024 merged commit 98db907 into alpha Aug 25, 2025
3 checks passed
@creamlike1024 creamlike1024 deleted the update-openai-websearch-price branch August 30, 2025 15:38
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