From 1d86fc84fe5c4c697ed58669810bd977aed21077 Mon Sep 17 00:00:00 2001 From: Cole McIntosh <82463175+colesmcintosh@users.noreply.github.com> Date: Sat, 7 Jun 2025 10:13:03 -0600 Subject: [PATCH] Update web search documentation for new provider support (xAI, VertexAI, Google AI Studio) (#11515) * Update web_search.md to include new supported providers and models, enhance web search options, and improve documentation for using web search with various AI models. * Update LiteLLM version in web_search.md to reflect the latest stable release. * Fix formatting in web_search.md for model declaration consistency. --- docs/my-website/docs/completion/web_search.md | 127 +++++++++++++++++- 1 file changed, 120 insertions(+), 7 deletions(-) diff --git a/docs/my-website/docs/completion/web_search.md b/docs/my-website/docs/completion/web_search.md index 7a67dc265e4..18ea8c9b4ff 100644 --- a/docs/my-website/docs/completion/web_search.md +++ b/docs/my-website/docs/completion/web_search.md @@ -8,9 +8,9 @@ Use web search with litellm | Feature | Details | |---------|---------| | Supported Endpoints | - `/chat/completions`
- `/responses` | -| Supported Providers | `openai` | +| Supported Providers | `openai`, `xai`, `vertex_ai`, `gemini` | | LiteLLM Cost Tracking | ✅ Supported | -| LiteLLM Version | `v1.63.15-nightly` or higher | +| LiteLLM Version | `v1.71.0+` | ## `/chat/completions` (litellm.completion) @@ -31,8 +31,12 @@ response = completion( "content": "What was a positive news story from today?", } ], + web_search_options={ + "search_context_size": "medium" # Options: "low", "medium", "high" + } ) ``` + @@ -40,10 +44,30 @@ response = completion( ```yaml model_list: + # OpenAI - model_name: gpt-4o-search-preview litellm_params: model: openai/gpt-4o-search-preview api_key: os.environ/OPENAI_API_KEY + + # xAI + - model_name: grok-3 + litellm_params: + model: xai/grok-3 + api_key: os.environ/XAI_API_KEY + + # VertexAI + - model_name: gemini-2-flash + litellm_params: + model: gemini-2.0-flash + vertex_project: your-project-id + vertex_location: us-central1 + + # Google AI Studio + - model_name: gemini-2-flash-studio + litellm_params: + model: gemini/gemini-2.0-flash + api_key: os.environ/GOOGLE_API_KEY ``` 2. Start the proxy @@ -64,7 +88,7 @@ client = OpenAI( ) response = client.chat.completions.create( - model="gpt-4o-search-preview", + model="grok-3", # or any other web search enabled model messages=[ { "role": "user", @@ -81,6 +105,7 @@ response = client.chat.completions.create( +**OpenAI (using web_search_options)** ```python showLineNumbers from litellm import completion @@ -98,6 +123,44 @@ response = completion( } ) ``` + +**xAI (using web_search_options)** +```python showLineNumbers +from litellm import completion + +# Customize search context size for xAI +response = completion( + model="xai/grok-3", + messages=[ + { + "role": "user", + "content": "What was a positive news story from today?", + } + ], + web_search_options={ + "search_context_size": "high" # Options: "low", "medium" (default), "high" + } +) +``` + +**VertexAI/Gemini (using web_search_options)** +```python showLineNumbers +from litellm import completion + +# Customize search context size for Gemini +response = completion( + model="gemini-2.0-flash", + messages=[ + { + "role": "user", + "content": "What was a positive news story from today?", + } + ], + web_search_options={ + "search_context_size": "low" # Options: "low", "medium" (default), "high" + } +) +``` @@ -112,7 +175,7 @@ client = OpenAI( # Customize search context size response = client.chat.completions.create( - model="gpt-4o-search-preview", + model="grok-3", # works with any web search enabled model messages=[ { "role": "user", @@ -127,6 +190,8 @@ response = client.chat.completions.create( + + ## `/responses` (litellm.responses) ### Quick Start @@ -253,25 +318,61 @@ print(response.output_text) -Use `litellm.supports_web_search(model="openai/gpt-4o-search-preview")` -> returns `True` if model can perform web searches +Use `litellm.supports_web_search(model="model_name")` -> returns `True` if model can perform web searches ```python showLineNumbers +# Check OpenAI models assert litellm.supports_web_search(model="openai/gpt-4o-search-preview") == True + +# Check xAI models +assert litellm.supports_web_search(model="xai/grok-3") == True + +# Check VertexAI models +assert litellm.supports_web_search(model="gemini-2.0-flash") == True + +# Check Google AI Studio models +assert litellm.supports_web_search(model="gemini/gemini-2.0-flash") == True ``` -1. Define OpenAI models in config.yaml +1. Define models in config.yaml ```yaml model_list: + # OpenAI - model_name: gpt-4o-search-preview litellm_params: model: openai/gpt-4o-search-preview api_key: os.environ/OPENAI_API_KEY model_info: supports_web_search: True + + # xAI + - model_name: grok-3 + litellm_params: + model: xai/grok-3 + api_key: os.environ/XAI_API_KEY + model_info: + supports_web_search: True + + # VertexAI + - model_name: gemini-2-flash + litellm_params: + model: gemini-2.0-flash + vertex_project: your-project-id + vertex_location: us-central1 + model_info: + supports_web_search: True + + # Google AI Studio + - model_name: gemini-2-flash-studio + litellm_params: + model: gemini/gemini-2.0-flash + api_key: os.environ/GOOGLE_API_KEY + model_info: + supports_web_search: True ``` 2. Run proxy server @@ -298,7 +399,19 @@ Expected Response "model_group": "gpt-4o-search-preview", "providers": ["openai"], "max_tokens": 128000, - "supports_web_search": true, # 👈 supports_web_search is true + "supports_web_search": true + }, + { + "model_group": "grok-3", + "providers": ["xai"], + "max_tokens": 131072, + "supports_web_search": true + }, + { + "model_group": "gemini-2-flash", + "providers": ["vertex_ai"], + "max_tokens": 8192, + "supports_web_search": true } ] }