Web Search
NagaAI supports web search integration for certain models. This feature allows models to access real-time information from the web to provide up-to-date and accurate responses.
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 the web_search_options parameter in your Chat Completions request.
Configuration
Using web_search_options
Include the web_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
- 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 parameters supported by the official Live Search in the xAI API. However, in our API, use web_search_options instead of search_parameters. All nested parameters are supported.
Basic Example
{
  "model": "grok-4-fast-reasoning",
  "web_search_options": {},
  "messages": [
    {
      "role": "user",
      "content": "What is the current date and time according to CET?"
    }
  ]
}
Getting Citations
To retrieve citations (sources) from web search results, include "return_citations": true in the web_search_options:
{
  "model": "grok-4-fast-reasoning",
  "web_search_options": {
    "return_citations": true
  },
  "messages": [
    {
      "role": "user",
      "content": "What are the latest AI developments?"
    }
  ]
}
Web search is optional for most OpenAI models. Include the web_search_options parameter to enable it.
For OpenAI models, web_search_options supports all parameters available in OpenAI's Responses API web_search tool, including:
- user_location: Specify the user's location to improve search relevance
- filters: Control which domains are allowed in search results
Basic Example
{
  "model": "gpt-4.1",
  "web_search_options": {},
  "messages": [
    {
      "role": "user",
      "content": "What are the latest developments in AI?"
    }
  ]
}
Advanced Example with Filters and Location
{
  "model": "gpt-4.1",
  "web_search_options": {
    "user_location": {
      "type": "approximate",
      "country": "GB",
      "city": "London",
      "region": "London"
    },
    "filters": {
      "allowed_domains": [
        "pubmed.ncbi.nlm.nih.gov",
        "clinicaltrials.gov",
        "www.who.int",
        "www.cdc.gov",
        "www.fda.gov"
      ]
    }
  },
  "messages": [
    {
      "role": "user",
      "content": "What are the latest clinical trials for cancer treatment?"
    }
  ]
}
Web search is optional for Google models. Include the web_search_options parameter to enable it.
Basic Example
{
  "model": "gemini-2.5-flash",
  "web_search_options": {},
  "messages": [
    {
      "role": "user",
      "content": "What's current weather in New York?"
    }
  ]
}
Web search is always enabled for Sonar models. It is a persistent feature and cannot be controlled or disabled using the web_search_options parameter.
Example
{
  "model": "sonar",
  "messages": [
    {
      "role": "user",
      "content": "What are the latest news in AI?"
    }
  ]
}
Retrieving Citations
Citations from web search results are available for all search-enabled models (Grok, OpenAI, Google, and Sonar). They can be accessed via the annotations 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:
[
  {
    "type": "url_citation",
    "url_citation": {
      "title": "Page title...",
      "url": "https://..."
    }
  }
]
The title field may not always be available depending on the model. Always use the url field to reference where information was retrieved from.