The Valyu Python SDK provides comprehensive access to all Valyu APIs, enabling you to build powerful AI applications with search, content extraction, answer generation, and deep research capabilities.Documentation Index
Fetch the complete documentation index at: https://docs.valyu.ai/llms.txt
Use this file to discover all available pages before exploring further.
Features
The SDK includes four core APIs:- Search API - Advanced search across web and proprietary data sources
- Contents API - Extract and process content from URLs with AI
- Answer API - AI-powered answer generation with search integration
- DeepResearch API - Async deep research with comprehensive reports
Installation
Install the Valyu Python SDK using pip:Authentication
Get your API key from Valyu Platform (free $10 credits included). Set up authentication in one of two ways:Environment Variable (Recommended)
Direct API Key
Quick Start
Here’s a simple example to get you started with search:Error Handling
The SDK includes built-in error handling and validation:Async Usage
AsyncValyu is the async/await counterpart to Valyu. It’s built
on httpx.AsyncClient and takes
exactly the same arguments, returns the same response objects, and
applies the same validation as the synchronous client. The only
difference is that every method is a coroutine — you await it
instead of calling it directly.
When to use it
Reach forAsyncValyu when any of these apply. If none apply, the
synchronous Valyu client is simpler and just as fast.
| Situation | Why async helps |
|---|---|
| You’re running several Valyu calls per user request (an agent fanning out sub-queries, multi-source research, etc.) | asyncio.gather runs them all in parallel instead of one after another. |
| You’re extracting many URLs with the Contents API | Dispatch them concurrently instead of polling one URL at a time. |
| You’re building a web service (FastAPI, Starlette, aiohttp) that calls Valyu during request handling | Await the call without tying up a worker thread; serve more concurrent users per process. |
You’re already inside an async code base (LLM SDKs, async database drivers, queue consumers) | Drop-in — no run_in_executor gymnastics. |
| You need to cap in-flight requests precisely | One asyncio.Semaphore is all you need; no thread pool to tune. |
Patterns
Single await
search — search_type,
max_num_results, included_sources, start_date, end_date,
category, country_code, relevance_threshold, source_biases,
instructions, fast_mode, etc. — works identically on async:
Fan-out — run many queries in parallel
Perfect for research agents or any place where you have a known, modest-size set of queries:Bounded fan-out — cap how many are in flight
When you have hundreds of queries but only want (for example) 20 hitting the API at once, use anasyncio.Semaphore:
max_connections=20 sizes the
underlying HTTP pool to match. Keep these two numbers aligned.
Stream results as they arrive
Useasyncio.as_completed when you want to process each result the
moment it’s ready rather than waiting for the whole batch:
Inside a FastAPI endpoint
Instantiate the client once at startup and share it across requests. Don’t create a freshAsyncValyu per request — you’d throw away the
connection pool every time.
Constructor options
| Parameter | Type | Description | Default |
|---|---|---|---|
api_key | Optional[str] | API key. Falls back to the VALYU_API_KEY env var. | None |
base_url | str | Base URL of the Valyu API. | https://api.valyu.ai/v1 |
max_connections | int | Maximum simultaneous HTTP connections the client pool will open. Raise when fan-out is high; lower on constrained environments. | 100 |
max_keepalive_connections | Optional[int] | Idle connections kept warm for reuse between requests. | max(20, max_connections // 5) |
timeout | float | Per-request timeout in seconds. Applies to every outbound request. | 600.0 |
http_client | Optional[httpx.AsyncClient] | Pre-configured client to use instead of the default. Ownership stays with the caller — aclose() won’t close it. | None |
Lifecycle
Preferasync with so the connection pool is released
deterministically:
aclose() during shutdown:
aclose() is idempotent. Calling it more than once is safe.
Bring your own httpx client
Pass an existing httpx.AsyncClient to reuse proxies, custom TLS
settings, or a shared connection pool across multiple libraries.
When you inject a client, ownership stays with you — aclose()
won’t close it:
Things to avoid
- Creating a new
AsyncValyuper request. You’ll tear down and rebuild the connection pool on every call — slower than sync. Hold one instance for the lifetime of your service or script. - Mixing
asyncio.runinside an already-running event loop. If you’re inside a framework that manages its own loop (Jupyter, FastAPI, etc.), call the coroutine withawait, notasyncio.run. - Leaving the client open at process exit. Always
aclose()or useasync with; otherwisehttpxwill warn about unclosed connections.
AsyncValyu currently exposes search, contents,
get_contents_job, and wait_for_contents_job. The remaining
endpoints (answer, deepresearch, datasources) are only
available on the synchronous Valyu client today; await-style
counterparts will follow.Next Steps
Explore the detailed documentation for each API:Search API
Advanced search across web and proprietary sources
Contents API
Extract and process web content with AI
Answer API
Generate AI-powered answers with search
DeepResearch API
Async deep research with comprehensive reports
Support
- Discord: Join our community
- GitHub: valyuAI/valyu-py
- Support: contact@valyu.ai

