Wire up Valyu Answer (search-grounded answers) with the TypeScript SDK.
Basic usage
Common patterns
Structured output
Pass a JSON schema tostructuredOutput and response.contents comes back as a structured object instead of a string. Detect it with typeof response.contents === "object":
Streaming
Setstreaming: true to receive the answer progressively as an async generator of typed chunks:
| Chunk type | Description |
|---|---|
search_results | Sources found (streamed first, before answer generation) |
content | Partial answer text chunk |
metadata | Final costs, token usage, and full search results |
done | Stream completed successfully |
error | An error occurred |
Reference
Parameters
Parameters
query (string, required) - the question to answer.| Parameter | Type | Description | Default |
|---|---|---|---|
structuredOutput | object | JSON schema for structured response | undefined |
systemInstructions | string | Custom AI instructions (max 2000 chars) | undefined |
searchType | "web" | "proprietary" | "all" | "news" | Search type before generating the answer | "all" |
dataMaxPrice | number | Max cost in USD for data retrieval (search costs only) | 1.0 |
countryCode | string | 2-letter ISO country code to bias results | undefined |
includedSources / excludedSources | string[] | Sources to search within / exclude | undefined |
startDate / endDate | string | Date filter (YYYY-MM-DD) | undefined |
fastMode | boolean | Reduced latency | false |
streaming | boolean | Stream chunks as they are generated | false |
Response format
Response format

