Features
- Chat Models:
ChatParallelWeb- Real-time web research chat completions - Search Tools:
ParallelWebSearchTool- Direct access to Parallel’s Search API - Extract Tools:
ParallelExtractTool- Clean content extraction from web pages - Streaming Support: Real-time response streaming
- Async/Await: Full asynchronous operation support
- OpenAI Compatible: Uses familiar OpenAI SDK patterns
- LangChain Integration: Seamless integration with LangChain ecosystem
Installation
Setup
- Get your API key from Parallel
- Set your API key as an environment variable:
Chat Models
ChatParallelWeb
TheChatParallelWeb class provides access to Parallel’s Chat API, which combines language models with real-time web research capabilities.
Basic Usage
Streaming Responses
Async Operations
Conversation Context
Configuration Options
| Parameter | Type | Default | Description |
|---|---|---|---|
model | str | "speed" | Parallel model name |
api_key | Optional[SecretStr] | None | API key (uses PARALLEL_API_KEY env var if not provided) |
base_url | str | "https://api.parallel.ai" | API base URL |
temperature | Optional[float] | None | Sampling temperature (ignored by Parallel) |
max_tokens | Optional[int] | None | Max tokens (ignored by Parallel) |
timeout | Optional[float] | None | Request timeout |
max_retries | int | 2 | Max retry attempts |
Real-Time Web Research
Parallel’s Chat API provides real-time access to web information, making it perfect for:- Current Events: Get up-to-date information about recent events
- Market Data: Access current stock prices, market trends
- Research: Find the latest research papers, developments
- Weather: Get current weather conditions
- News: Access breaking news and recent articles
Integration with LangChain
Chains
Agents
Search API
The Search API provides direct access to Parallel’s web search capabilities, returning structured, compressed excerpts optimized for LLM consumption.ParallelWebSearchTool
The search tool provides direct access to Parallel’s Search API:Search API Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
objective | Optional[str] | None | Natural-language description of research goal |
search_queries | Optional[List[str]] | None | Specific search queries (max 5, 200 chars each) |
max_results | int | 10 | Maximum results to return (1-40) |
excerpts | Optional[dict] | None | Excerpt settings (e.g., {'max_chars_per_result': 1500}) |
mode | Optional[str] | None | Search mode: ‘one-shot’ for comprehensive results, ‘agentic’ for token-efficient results |
fetch_policy | Optional[dict] | None | Policy for cached vs live content (e.g., {'max_age_seconds': 86400, 'timeout_seconds': 60}) |
api_key | Optional[SecretStr] | None | API key (uses env var if not provided) |
base_url | str | "https://api.parallel.ai" | API base URL |
Search with Specific Queries
You can provide specific search queries instead of an objective:Tool Usage in Agents
The search tool works seamlessly with LangChain agents:Extract API
The Extract API provides clean content extraction from web pages, returning structured markdown-formatted content optimized for LLM consumption.ParallelExtractTool
The extract tool extracts clean, structured content from web pages:Extract with Search Objective and Advanced Options
Focus extraction on specific topics using search objectives, with control over excerpts and fetch policy:Extract with Search Queries
Extract content relevant to specific search queries:Content Length Control
Extract API Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
urls | List[str] | Required | List of URLs to extract content from |
search_objective | Optional[str] | None | Natural language objective to focus extraction |
search_queries | Optional[List[str]] | None | Specific keyword queries to focus extraction |
excerpts | Union[bool, ExcerptSettings] | True | Include relevant excerpts (focused on objective/queries if provided) |
full_content | Union[bool, FullContentSettings] | False | Include full page content |
fetch_policy | Optional[FetchPolicy] | None | Cache vs live content policy |
max_chars_per_extract | Optional[int] | None | Maximum characters per extraction (tool-level setting) |
api_key | Optional[SecretStr] | None | API key (uses env var if not provided) |
base_url | str | "https://api.parallel.ai" | API base URL |
Extract Error Handling
The extract tool gracefully handles failed extractions:Async Extract
Error Handling
Examples
See theexamples/ and docs/ directories for complete working examples:
examples/chat_example.py- Chat model usage examplesdocs/search_tool.ipynb- Search tool examples and tutorialsdocs/extract_tool.ipynb- Extract tool examples and tutorials
- Basic synchronous usage
- Streaming responses
- Async operations
- Conversation management
- Tool usage in agents