Web Search

Search the web and get results with optional content scraping.

Web Search performs searches across the web and returns results with titles, descriptions, and URLs. Optionally scrape each result to get full content.

Pricing

$0.0076 per 10 results (or fewer), counted on the results actually returned (web, news, and image results together). Billed in buckets:

Results returnedCharges
0Nothing
1-101x
11-202x
21-303x

When using scrape_options, each scraped result is billed separately at the Web Scrape rate ($0.0038 per page, plus any extra pages its formats add).

Response shape

Results are grouped by source under data:

{
  "id": "...",
  "data": {
    "web": [
      { "title": "...", "description": "...", "url": "https://..." }
    ],
    "news": [
      { "title": "...", "snippet": "...", "url": "https://...", "date": "..." }
    ],
    "images": [
      { "title": "...", "image_url": "https://...", "url": "https://..." }
    ]
  },
  "warning": "..."
}

A group can be missing (for example news and images when you did not ask for those sources), so guard with ?? []. warning appears only when there is one. With scrape_options, each web and news result also carries the scraped fields (markdown, html, ...).

Basic usage

const result = await client.post('/v1/tools/web_search', {
  body: {
    query: 'best practices for API design',
    limit: 10
  }
});

for (const item of result.data.web ?? []) {
  console.log(item.title);
  console.log(item.url);
  console.log(item.description);
}

Search with content scraping

Get full page content for each result in a single call:

const result = await client.post('/v1/tools/web_search', {
  body: {
    query: 'machine learning tutorials',
    limit: 5,
    scrape_options: {
      formats: ['markdown'],
      only_main_content: true
    }
  }
});

for (const item of result.data.web ?? []) {
  console.log(item.title);
  console.log(item.markdown);  // Full page content
}

Filter by domain

Search only specific sites:

const result = await client.post('/v1/tools/web_search', {
  body: {
    query: 'react hooks',
    include_domains: ['reactjs.org', 'github.com'],
    limit: 10
  }
});

Or exclude certain domains:

const result = await client.post('/v1/tools/web_search', {
  body: {
    query: 'javascript frameworks',
    exclude_domains: ['w3schools.com'],
    limit: 10
  }
});

Search for recent content:

// Past day
const result = await client.post('/v1/tools/web_search', {
  body: {
    query: 'AI news',
    tbs: 'qdr:d',
    limit: 10
  }
});
Time filtertbs value
Past hourqdr:h
Past dayqdr:d
Past weekqdr:w
Past monthqdr:m
Past yearqdr:y

Get results relevant to a specific location:

const result = await client.post('/v1/tools/web_search', {
  body: {
    query: 'coffee shops',
    location: 'us',
    limit: 10
  }
});

Common use cases

Research automation

async function research(topic: string) {
  const results = await client.post('/v1/tools/web_search', {
    body: {
      query: topic,
      limit: 10,
      scrape_options: {
        formats: ['markdown'],
        only_main_content: true
      }
    }
  });

  return (results.data.web ?? []).map(r => ({
    source: r.url,
    content: r.markdown
  }));
}

RAG context gathering

async function getContext(question: string) {
  const results = await client.post('/v1/tools/web_search', {
    body: {
      query: question,
      limit: 5,
      scrape_options: {
        formats: ['markdown'],
        only_main_content: true
      }
    }
  });

  return (results.data.web ?? [])
    .map(r => r.markdown)
    .join('\n\n---\n\n');
}

API Reference

For complete parameter documentation, see the API Reference.