Wire up Valyu Answer (search-grounded answers) with the Python SDK.
Basic usage
Common patterns
Structured output
Pass a JSON schema tostructured_output and response.contents comes back as a structured object (a dict) instead of a string. Detect it with isinstance(response.contents, dict):
Streaming
Setstreaming=True to receive the answer progressively. The method returns a generator yielding 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 (str, required) - the question to answer.| Parameter | Type | Description | Default |
|---|---|---|---|
structured_output | dict | JSON schema for structured response | None |
system_instructions | str | Custom AI instructions (max 2000 chars) | None |
search_type | "web" | "proprietary" | "all" | "news" | Search type before generating the answer | "all" |
data_max_price | float | Max cost in USD for data retrieval (search costs only) | 1.0 |
country_code | str | 2-letter ISO country code to bias results | None |
included_sources / excluded_sources | List[str] | Sources to search within / exclude | None |
start_date / end_date | str | Date filter (YYYY-MM-DD) | None |
fast_mode | bool | Reduced latency | False |
streaming | bool | Stream chunks as they are generated | False |
Response format
Response format

