Skip to main content

Overview

Use Web Search when you need ranked search results and want to decide what to do with them yourself. It does not call an LLM. For generated answers with citations, use the Answer API. For full page content after search, combine Web Search with the Scraper API.

Endpoint

POST /api/v2/web_search

Quickstart

import { LLMLayerClient } from 'llmlayer';

const client = new LLMLayerClient({
  apiKey: process.env.LLMLAYER_API_KEY,
});

const response = await client.searchWeb({
  query: 'AI regulation updates',
  searchType: 'news',
  recency: 'week',
  location: 'us',
});

for (const result of response.results.slice(0, 3)) {
  console.log(result.title, result.link);
}

Search Types

TypeUse it forNotes
generalStandard web resultsDefault
newsRecent news articlesSupports recency
shoppingProduct listingsResult fields vary by source
videosVideo searchUseful before transcript extraction
imagesImage resultsReturns image-oriented metadata
scholarAcademic papersBest effort availability by query

Request Parameters

ParameterTypeRequiredDefaultDescription
querystringYes-Search query
search_typestringNogeneralgeneral, news, shopping, videos, images, or scholar
locationstringNousCountry/location hint
recencystringNonullhour, day, week, month, or year
domain_filterstring[]NonullInclude domains, or exclude with a leading -
HTTP requests use snake_case. The TypeScript SDK uses camelCase, for example searchType and domainFilter.

Response

{
  "results": [
    {
      "title": "Example result",
      "link": "https://www.ycombinator.com/blog",
      "snippet": "Short description..."
    }
  ],
  "cost": 0.002
}
FieldTypeDescription
resultsarraySearch results. Shape depends on search_type.
costnumber | nullCost in USD for the request.

Common Patterns

response = client.search_web(
    query="retrieval augmented generation",
    domain_filter=["arxiv.org", "openai.com", "-reddit.com"],
)

Search then scrape

const search = await client.searchWeb({
  query: 'best practices for LLM evaluation',
  searchType: 'general',
});

const firstUrl = search.results[0]?.link;
if (typeof firstUrl === 'string') {
  const page = await client.scrape(firstUrl, {
    formats: ['markdown'],
    mainContentOnly: true,
  });
  console.log(page.markdown);
}

Pricing

Web Search costs $0.002 per request.

Errors

StatusMeaning
400Missing or invalid query/search parameters
401Missing or invalid LLMLayer API key
429Rate limit exceeded
500Search provider or internal error
See Errors & Refunds for the shared error format.

More Examples

Search + Scrape Pipeline

Find pages, scrape full content, then answer with sources.

Answer API

Use search results directly with an LLM.