fix(anthropic): set supports_web_search on current Claude models priced for web search - #33920
Conversation
…ed for web search
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
Greptile SummaryThis PR fixes a metadata gap where Anthropic-direct model entries priced for the built-in web-search tool (
Confidence Score: 4/5The JSON changes are correct and targeted; the test file introduces a module-level state mutation without rollback that can affect other tests in the same session. The core fix — adding tests/test_litellm/test_anthropic_web_search_model_metadata.py — the
|
| Filename | Overview |
|---|---|
| model_prices_and_context_window.json | Adds "supports_web_search": true to 16 Anthropic-direct entries that already carried search_context_cost_per_query; no unrelated models touched and no existing flags removed. |
| litellm/model_prices_and_context_window_backup.json | Mirror of main file changes — identical "supports_web_search": true additions for the same 16 models; backup is kept in sync. |
| tests/test_litellm/test_anthropic_web_search_model_metadata.py | New test file verifying the flag fix and a forward-looking invariant; litellm.model_cost is mutated without monkeypatch rollback (test isolation defect), and the invariant is not applied to the backup file. |
Reviews (1): Last reviewed commit: "fix(anthropic): set supports_web_search ..." | Re-trigger Greptile
| def test_supports_web_search_resolves_true(monkeypatch, model): | ||
| monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") | ||
| litellm.model_cost = litellm.get_model_cost_map(url="") | ||
| assert litellm.supports_web_search(model=model) is True |
There was a problem hiding this comment.
litellm.model_cost mutation not rolled back after test
litellm.model_cost is overwritten with a direct assignment, which monkeypatch does not track and therefore does not restore after the test finishes. Every test that runs later in the same pytest session will see the local-backup cost map instead of whatever was in litellm.model_cost before. Swapping to monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url="")) lets pytest restore the original value automatically.
| def test_anthropic_entries_with_search_billing_advertise_web_search(): | ||
| """Any Anthropic-direct model priced for the web search tool must set the flag. | ||
|
|
||
| ``search_context_cost_per_query`` is the billing metadata for Anthropic's web | ||
| search tool, so an entry that carries it while omitting ``supports_web_search`` | ||
| would be silently excluded by ``supports_web_search`` / router web-search filtering. | ||
| """ | ||
| missing = tuple( | ||
| model | ||
| for model, info in _main().items() | ||
| if isinstance(info, dict) | ||
| and info.get("litellm_provider") == "anthropic" | ||
| and "search_context_cost_per_query" in info | ||
| and info.get("supports_web_search") is not True | ||
| ) | ||
| assert missing == (), f"Anthropic entries priced for web search but missing the flag: {missing}" |
There was a problem hiding this comment.
Invariant not enforced for the backup map
test_anthropic_entries_with_search_billing_advertise_web_search verifies that every anthropic-provider entry in the main file with search_context_cost_per_query also sets supports_web_search, but only checks model_prices_and_context_window.json. The backup file has an equivalent enforcement gap: test_backup_matches_main only spot-checks ISSUE_MODELS, so a future model added to the main file that accidentally omits supports_web_search in the backup would pass all tests.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…5 entries Bedrock and bedrock_converse regional entries for claude-sonnet-4, claude-sonnet-4-5, claude-sonnet-4-6, and claude-sonnet-5 were missing supports_web_search: true, even though every other capability flag (vision, function_calling, prompt_caching) was correctly set and Anthropic's web_search_20250305 tool works identically on Bedrock as on the direct API. This caused litellm.supports_web_search() to return False and Router.filter_web_search_deployments() to incorrectly exclude these Bedrock deployments from web-search-tagged requests. Complementary to BerriAI#33920, which covers the Anthropic-direct (litellm_provider: anthropic) entries for the same underlying issue; this PR covers the Bedrock/bedrock_converse regional variants that PR does not touch. Fixes BerriAI#33919 (Bedrock half)
Relevant issues
Fixes #33919
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Every current-generation Anthropic-direct entry already carries
search_context_cost_per_query(the billing metadata for Anthropic'sweb_search_20250305tool), yet omittedsupports_web_search, solitellm.supports_web_search(...)returnedFalseand Router web-search filtering excluded the deployments.Before (base
litellm_internal_staging), the issue repro printedFalsefor all listed models exceptclaude-3-7-sonnet-20250219After (commit
68a3a56f70cee50d45cc5d7c0e6a423876c07674):Live Anthropic web search confirming the flag is accurate (real API calls, commit
68a3a56f70cee50d45cc5d7c0e6a423876c07674):Type
🐛 Bug Fix
Changes
Added
"supports_web_search": trueto every Anthropic-direct (litellm_provider: anthropic) entry that already prices the web search tool viasearch_context_cost_per_querybut was missing the capability flag; this coversclaude-sonnet-4-20250514,claude-sonnet-4-5,claude-sonnet-4-6,claude-sonnet-5,claude-opus-4-1,claude-opus-4-1-20250805,claude-opus-4-20250514,claude-4-opus-20250514,claude-opus-4-5,claude-opus-4-5-20251101,claude-opus-4-6,claude-opus-4-6-20260205,claude-opus-4-7,claude-opus-4-7-20260416,claude-fable-5andclaude-opus-4-8. The same entries were updated in the bundled backup map so the two stay in syncAdded
tests/test_litellm/test_anthropic_web_search_model_metadata.py. Beyond checking the specific models from the issue, it enforces the invariant that any Anthropic-direct entry priced for web search (search_context_cost_per_querypresent) must setsupports_web_search, so future model additions can't silently reintroduce the drift; it also verifies the flag resolves throughlitellm.supports_web_searchand that the backup map matches the canonical fileFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/a3ffe74142e640118168500f7431c768