Supported Models Grok, OpenAI (most models), Google, and Sonar models
support web search.
Overview
Web search enables models to retrieve and use current information from the internet when responding to queries. You control web search behavior through theweb_search_options parameter in your Chat Completions request.
Configuration
Using web_search_options
Include theweb_search_options parameter in your request to enable and configure web search behavior for supported models.
Model-Specific Behavior
Below are examples and configuration details for each provider that supports web search:- Grok
- OpenAI
- Google
- Sonar
Web search is optional for Grok models. To enable it, include the
web_search_options parameter with an empty object {} or with specific configuration options.We support all functionality provided by the official Search Tools in the xAI API. This allows for advanced search capabilities through web_search (internet search) and x_search (X platform search) configurations within web_search_options.Supported Parameters
Theweb_search_options object accepts two main configuration objects:-
web_search: Configuration for general internet search.allowed_domains(array): List of domains to include in search.excluded_domains(array): List of domains to exclude.enable_image_understanding(boolean): Enable image analysis in search results.
-
x_search: Configuration for searching the X platform.allowed_x_handles(array): Filter tweets from specific handles.excluded_x_handles(array): Exclude tweets from specific handles.from_date(string): Filter tweets after this date (ISO format).to_date(string): Filter tweets before this date (ISO format).enable_image_understanding(boolean): Enable image analysis in tweets.enable_video_understanding(boolean): Enable video analysis in tweets.
Basic Example
Advanced Example
Retrieving Citations
Citations from web search results are available for all search-enabled models (Grok, OpenAI, Google, and Sonar). They can be accessed via theannotations field in the response.
Accessing Citations
The location of citations depends on whether you’re using streaming or non-streaming mode:- Non-streaming responses:
choices[0].message.annotations - Streaming responses:
choices[0].delta.annotations
Citation Structure
Citations are returned as an array. Each citation contains the source URL and may include the page title:The
title field may not always be available depending on the model. Always
use the url field to reference where information was retrieved from.