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
Type Use it for Notes generalStandard web results Default newsRecent news articles Supports recency shoppingProduct listings Result fields vary by source videosVideo search Useful before transcript extraction imagesImage results Returns image-oriented metadata scholarAcademic papers Best effort availability by query
Request Parameters
Parameter Type Required Default Description querystringYes - Search query search_typestringNo generalgeneral, news, shopping, videos, images, or scholarlocationstringNo usCountry/location hint recencystringNo nullhour, day, week, month, or yeardomain_filterstring[]No nullInclude 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
}
Field Type Description resultsarraySearch results. Shape depends on search_type. costnumber | nullCost in USD for the request.
Common Patterns
Domain-constrained search
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
Status Meaning 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.