Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/my-website/docs/providers/azure/azure_responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ You can also call the Azure Responses API via the `/chat/completions` endpoint.
from litellm import completion
import os

os.environ["AZURE_API_BASE"] = "https://my-endpoint-sweden-berri992.openai.azure.com/"
os.environ["AZURE_API_BASE"] = "https://my-azure-endpoint.openai.azure.com/"
os.environ["AZURE_API_VERSION"] = "2023-03-15-preview"
os.environ["AZURE_API_KEY"] = "my-api-key"

Expand All @@ -268,7 +268,7 @@ model_list:
litellm_params:
model: azure/responses/my-custom-o1-pro
api_key: os.environ/AZURE_API_KEY
api_base: https://my-endpoint-sweden-berri992.openai.azure.com/
api_base: https://my-azure-endpoint.openai.azure.com/
api_version: 2023-03-15-preview
```

Expand Down
2 changes: 1 addition & 1 deletion docs/my-website/docs/proxy/team_model_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ curl -L -X POST 'http://0.0.0.0:4000/model/new' \
"model": "openai/gpt-4o",
"custom_llm_provider": "openai",
"api_key": "******ccb07",
"api_base": "https://my-endpoint-sweden-berri992.openai.azure.com",
"api_base": "https://my-azure-endpoint.openai.azure.com",
"api_version": "2023-12-01-preview"
},
"model_info": {
Expand Down
2 changes: 1 addition & 1 deletion docs/my-website/docs/realtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Run this script using node - `node test.js`
const WebSocket = require("ws");

const url = "ws://0.0.0.0:4000/v1/realtime?model=openai-gpt-4o-realtime-audio";
// const url = "wss://my-endpoint-sweden-berri992.openai.azure.com/openai/realtime?api-version=2024-10-01-preview&deployment=gpt-4o-realtime-preview";
// const url = "wss://my-azure-endpoint.openai.azure.com/openai/realtime?api-version=2024-10-01-preview&deployment=gpt-4o-realtime-preview";
const ws = new WebSocket(url, {
headers: {
"api-key": `sk-1234`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,8 @@ def response_object_includes_web_search_call(
)
if has_url_citations:
return True
# Fallback: Check usage object for providers that use usage instead of annotations
# (e.g., Vertex AI Gemini uses usage.prompt_tokens_details.web_search_requests)
if usage is not None:
# Vertex AI Gemini uses usage.prompt_tokens_details.web_search_requests
if (
hasattr(usage, "prompt_tokens_details")
and usage.prompt_tokens_details is not None
Expand All @@ -335,6 +334,15 @@ def response_object_includes_web_search_call(
and usage.prompt_tokens_details.web_search_requests is not None
):
return True
# Anthropic Claude (direct API and Vertex AI) uses server_tool_use.web_search_requests.
# Without this check, Claude ModelResponse always falls through to return False
# and _handle_web_search_cost() is never called.
if (
hasattr(usage, "server_tool_use")
and usage.server_tool_use is not None
and usage.server_tool_use.web_search_requests is not None
):
return True
Comment on lines +337 to +345

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.

P2 web_search_requests == 0 triggers web-search cost path unnecessarily

The guard usage.server_tool_use.web_search_requests is not None returns True even when web_search_requests == 0 (zero actual searches). This causes response_object_includes_web_search_call to report True for a response that contained no web searches at all.

While downstream get_cost_for_anthropic_web_search would compute 0 * rate = 0.0, returning True here is semantically incorrect and mirrors a pre-existing gap also present in the Gemini branch. The parallel Gemini check (prompt_tokens_details.web_search_requests is not None) has the same issue, so at minimum be consistent — but consider tightening both to > 0:

Suggested change
# Anthropic Claude (direct API and Vertex AI) uses server_tool_use.web_search_requests.
# Without this check, Claude ModelResponse always falls through to return False
# and _handle_web_search_cost() is never called.
if (
hasattr(usage, "server_tool_use")
and usage.server_tool_use is not None
and usage.server_tool_use.web_search_requests is not None
):
return True
if (
hasattr(usage, "server_tool_use")
and usage.server_tool_use is not None
and usage.server_tool_use.web_search_requests is not None
and usage.server_tool_use.web_search_requests > 0
):
return True

Evidence: test_anthropic_chat_transformation.py line 1208 explicitly asserts usage.server_tool_use.web_search_requests == 0 as a valid server-returned value.

return False
elif isinstance(response_object, ResponsesAPIResponse):
# response api explicitly includes web_search_call in the output
Expand Down
12 changes: 12 additions & 0 deletions litellm/llms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ def get_cost_for_web_search_request(

return get_cost_for_anthropic_web_search(model_info=model_info, usage=usage)
elif custom_llm_provider.startswith("vertex_ai"):
# Anthropic Claude models on Vertex AI populate server_tool_use.web_search_requests
# (same as the direct Anthropic API), not prompt_tokens_details.web_search_requests
# (which is the Gemini field). Route claude-* models to the Anthropic calculator.
model_key: str = model_info.get("key", "") if model_info else ""
if "claude" in model_key.lower():
from .anthropic.cost_calculation import get_cost_for_anthropic_web_search

verbose_logger.debug(
"vertex_ai/claude model detected — routing web search cost to Anthropic calculator"
)
return get_cost_for_anthropic_web_search(model_info=model_info, usage=usage)
Comment on lines +40 to +47

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.

P2 Inline import inside function body

The new import at line 42 (from .anthropic.cost_calculation import get_cost_for_anthropic_web_search) is placed inside the function body. CLAUDE.md requires module-level imports unless inline placement is strictly required to avoid a circular import.

All other branches in this file already follow the same inline-import pattern, so this is consistent — but if refactoring ever brings the imports to module-level, this new one should move too. Consider a top-of-file import with a conditional guard, or document the circular-import reason in a comment, so future contributors know the inline pattern is intentional.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


from .vertex_ai.gemini.cost_calculator import (
cost_per_web_search_request as cost_per_web_search_request_vertex_ai,
)
Expand Down
10 changes: 5 additions & 5 deletions tests/llm_translation/test_azure_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ def test_azure_extra_headers(input, call_type, header_value):
"api_base, model, expected_endpoint",
[
(
"https://my-endpoint-sweden-berri992.openai.azure.com",
"https://fake-azure-endpoint.invalid",
"dall-e-3-test",
"https://my-endpoint-sweden-berri992.openai.azure.com/openai/deployments/dall-e-3-test/images/generations?api-version=2023-12-01-preview",
"https://fake-azure-endpoint.invalid/openai/deployments/dall-e-3-test/images/generations?api-version=2023-12-01-preview",
),
(
"https://my-endpoint-sweden-berri992.openai.azure.com/openai/deployments/my-custom-deployment",
"https://fake-azure-endpoint.invalid/openai/deployments/my-custom-deployment",
"dall-e-3",
"https://my-endpoint-sweden-berri992.openai.azure.com/openai/deployments/my-custom-deployment/images/generations?api-version=2023-12-01-preview",
"https://fake-azure-endpoint.invalid/openai/deployments/my-custom-deployment/images/generations?api-version=2023-12-01-preview",
),
],
)
Expand Down Expand Up @@ -261,7 +261,7 @@ def test_azure_openai_gpt_4o_naming(monkeypatch):

client = AzureOpenAI(
api_key="test-api-key",
base_url="https://my-endpoint-sweden-berri992.openai.azure.com",
base_url="https://fake-azure-endpoint.invalid",
api_version="2023-12-01-preview",
)

Expand Down
Loading