Web Search
Enable LLMs to search the web for real-time information.
Web Search is a built-in tool that allows LLMs to search the web for real-time information. When enabled, the model can autonomously decide when to search the web to answer queries about current events, recent data, or facts that may have changed after its training cutoff.
Pricing
| Depth | Price |
|---|---|
| Basic | $4.00 / 1,000 calls |
| Advanced | $7.00 / 1,000 calls |
Each call gets up to 20 results. The cost is billed separately from token usage.
How it works
Unlike function tools that you define yourself, Web Search is a built-in tool
type. Simply include { type: 'web_search' } in your tools array, and the
model will automatically have access to web search capabilities.
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.aivene.com/v1',
apiKey: process.env.AIVENE_API_KEY
});
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'user', content: 'What are the latest news about SpaceX?' }
],
tools: [
{ type: 'web_search' }
]
});
console.log(response.choices[0].message.content);Configuration options
You can customize Web Search behavior with optional parameters:
typestringrequiredMust be "web_search".
search_depthstringoptionalSearch depth level. "basic" for faster, cheaper searches or "advanced" for
more comprehensive results. Defaults to "basic".
countrystringoptionalTwo-letter country code to bias results (e.g., "us", "id", "jp").
include_domainsstring[]optionalList of domains to restrict search results to. Example: ["github.com", "stackoverflow.com"].
exclude_domainsstring[]optionalList of domains to exclude from search results. Example: ["pinterest.com"].
Example with configuration
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'user', content: 'What are the trending tech stocks today?' }
],
tools: [
{
type: 'web_search',
search_depth: 'advanced',
country: 'us',
include_domains: ['bloomberg.com', 'reuters.com', 'wsj.com']
}
]
});Search parameters
When the model decides to search, it can specify additional parameters:
| Parameter | Type | Description |
|---|---|---|
query | string | The search query (required) |
max_results | number | Number of results to return (1-20) |
topic | string | Category: "general", "news", or "finance" |
time_range | string | Recency filter: "day", "week", "month", or "year" |
The model automatically chooses appropriate values based on the user's question.
Combining with other tools
Web Search works alongside your custom function tools:
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'user', content: 'Search for the latest iPhone price and save it to my database' }
],
tools: [
{ type: 'web_search' },
{
type: 'function',
function: {
name: 'save_to_database',
description: 'Save data to the database',
parameters: {
type: 'object',
properties: {
key: { type: 'string' },
value: { type: 'string' }
},
required: ['key', 'value']
}
}
}
]
});Best practices
- Use basic depth for speed — Advanced search is more thorough but costs more and takes longer
- Restrict domains when relevant — Use
include_domainsto get results from trusted sources - Combine with web_fetch — Use Web Search to find URLs, then Web Fetch to read the content
- Let the model decide — The model is trained to know when web search is appropriate