Skip to content

fix(cost-map): bill Azure OpenAI web search at the Grounding with Bing rate - #48367

Closed
kelp-aryan wants to merge 1 commit into
BerriAI:mainfrom
kelp-aryan:fix-azure-web-search-bing-price
Closed

kelp-aryan wants to merge 1 commit into
BerriAI:mainfrom
kelp-aryan:fix-azure-web-search-bing-price

Conversation

@kelp-aryan

@kelp-aryan kelp-aryan commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Azure OpenAI's web search tool runs on Grounding with Bing, and Microsoft bills it at $14 per 1,000 Bing requests. LiteLLM billed Azure web search at OpenAI's $10 per 1,000, or at $0 on Azure models whose price row had no search price, so proxy spend and budgets under-counted it. This PR prices every Azure row that supports web search at $0.014 per request and adds tests that keep new Azure rows in line.

Details

TLDR

Problem this solves:

  • Azure web search is billed $0.01 per request, not $0.014
  • 73 azure rows bill web search at $0
  • Their OpenAI twins do price web search

How it solves it:

  • Sets search_context_cost_per_query to 0.014 on 51 azure rows
  • Adds the same price to 73 azure rows missing it
  • Tests pin the price and the twin coverage

User Flow

Before: a proxy admin running Azure OpenAI with web search sees search spend recorded low, or at $0

  1. A developer sends POST https://litellm-domain/v1/responses with "model": "azure/gpt-5-mini" and "tools": [{"type": "web_search"}]
  2. Azure answers after 3 Bing requests (tool_usage.web_search.num_requests: 3)
  3. The response header x-litellm-response-cost-tool-usage reads 0.0, and key spend counts no search cost

After: the same request records the Bing requests at Microsoft's rate

  1. The developer sends the same POST https://litellm-domain/v1/responses
  2. Azure answers after 3 Bing requests
  3. x-litellm-response-cost-tool-usage reads 0.042 (3 x $0.014), and key spend includes it

Relevant issues

Fixes #48365

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
    • Required checks cost-map-guard, lint passed and smoke passed pass. unit passed fails only on test_token_counter_loads_a_custom_tokenizer_off_the_event_loop in proxy-infra-root (event loop stalled 0.111s against a 0.104s limit; 4328 other tests passed). That timing test fails the same way on other open PRs and doesn't touch pricing, so a re-run should clear it. I can't re-run jobs from a fork.
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review
    • Codecov (all changed lines covered) and CodSpeed (no performance change) have finished with nothing to address. No Greptile review has run on this commit yet.

Screenshots / Proof of Fix

Real responses from Azure OpenAI deployments on Microsoft Foundry (/v1/responses, web_search tool), captured through a LiteLLM 1.106.4 proxy. The Before header values are what that proxy charged live. Both Before and After price the same saved response bodies with each checkout's cost calculator. I don't have a raw Azure key to run a second proxy on this branch.

StandardBuiltInToolCostTracking.get_cost_for_built_in_tools(
    model=f"azure/{model}", response_object=ResponsesAPIResponse.model_validate(body),
    usage=None, custom_llm_provider="azure", standard_built_in_tools_params=None,
)

Before (dddbaa8)

azure/gpt-5.6-luna, 1 Bing request

  1. Live proxy header: x-litellm-response-cost-tool-usage: 0.01
  2. Cost calculator at dddbaa8: num_requests=1 web_search_fee=$0.010000

azure/gpt-5-mini, 3 Bing requests

  1. Live proxy header: x-litellm-response-cost-tool-usage: 0.0
  2. Cost calculator at dddbaa8: num_requests=3 web_search_fee=$0.000000

After (d6ce0fb)

azure/gpt-5.6-luna, 1 Bing request

  1. Cost calculator at d6ce0fb: num_requests=1 web_search_fee=$0.014000

azure/gpt-5-mini, 3 Bing requests

  1. Cost calculator at d6ce0fb: num_requests=3 web_search_fee=$0.042000

Tests:

uv run pytest tests/unit/test_model_prices_and_context_window.py tests/unit/litellm_core_utils/llm_cost_calc/test_tool_call_cost_tracking.py tests/unit/test_cost_map_guard.py tests/unit/litellm_core_utils/llm_cost_calc/test_web_search_logged_cost.py

The 4 new tests fail on the dddbaa8 cost map and pass here. test_embedding_success_logging_and_spend_log_carry_no_forwarded_credentials in tests/unit/test_cost_calculator.py fails locally on both dddbaa8 and this branch with ModuleNotFoundError: websockets, which is a local environment gap.

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • The rate comes from Microsoft's public docs, not an invoice

Low

  • The 73 newly priced rows were chosen by their OpenAI twin pricing web search; their supports_web_search flags are unchanged
  • docs/search/bing_grounding still says web search mode pays no per-search fee; left for a separate change

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

…g rate

Azure OpenAI's web_search tool runs on Grounding with Bing and is billed per
Bing request ($14 per 1,000). azure/* rows copied OpenAI's $0.01, and 73 azure
rows whose OpenAI model prices web search had no search price, so they billed $0.
@codspeed

codspeed Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 35 untouched benchmarks


Comparing kelp-aryan:fix-azure-web-search-bing-price (d6ce0fb) with main (72f1ac4)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (dddbaa8) during the generation of this report, so 72f1ac4 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Absorbed into the rolling registry PR #48188 with the Bing rate and both tests, credited as co-author. Closing as superseded

@kelp-aryan
kelp-aryan deleted the fix-azure-web-search-bing-price branch November 6, 2026 15:24
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.

[Bug]: Azure OpenAI web_search fee billed at OpenAI's $0.01 per request, or $0 on some azure/* models, instead of the Grounding with Bing rate

1 participant