Feature

Web Search

Give AI models access to real-time web information for current and accurate responses

Real-Time Information

Web search enables AI models to access current information beyond their training cutoff, search for specific facts, and provide citations for their responses. Perfect for news, research, and fact-checking applications.

Live Web Access

Search billions of web pages in real-time

Current Information

Access news and data from today

Source Citations

Get verifiable sources for all claims

Basic Web Search

Enable web search for any request with simple configuration:

Enable Web Searchpython
from openai import OpenAI

client = OpenAI(
    base_url="https://api.parrotrouter.com/v1",
    api_key="your-api-key"
)

# Basic web search
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "What are the latest developments in quantum computing?"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Results": "5"  # Number of results to include
    }
)

print(response.choices[0].message.content)
# Output includes current information with sources

# Access search metadata
search_info = json.loads(response.headers.get('X-Search-Metadata', '{}'))
print(f"Sources used: {len(search_info['sources'])}")
for source in search_info['sources']:
    print(f"- {source['title']} ({source['url']})")

# Search with specific parameters
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "Find recent scientific papers on CRISPR gene editing"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Config": json.dumps({
            "results": 10,
            "time_range": "month",  # past month only
            "regions": ["US", "EU"],
            "safe_search": "moderate",
            "search_type": "academic"  # academic, news, general
        })
    }
)

Advanced Search Features

Domain-Specific Search

Search specific websites or domains for targeted information.

# Search specific domains
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "What is the latest iPhone pricing?"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Domains": "apple.com,macrumors.com,9to5mac.com",
        "X-Exclude-Domains": "ebay.com,amazon.com"  # Exclude marketplaces
    }
)

# Search academic sources
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "Recent research on Alzheimer's treatment"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Config": json.dumps({
            "domains": [
                "pubmed.ncbi.nlm.nih.gov",
                "nature.com",
                "science.org",
                "nejm.org"
            ],
            "require_peer_review": True,
            "min_year": 2023
        })
    }
)

Real-Time News Search

Access breaking news and current events.

# Search recent news
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "What happened in the stock market today?"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Config": json.dumps({
            "search_type": "news",
            "time_range": "24h",
            "sort": "relevance",  # or "date"
            "sources": [
                "reuters.com",
                "bloomberg.com",
                "wsj.com",
                "ft.com"
            ],
            "include_summaries": True
        })
    }
)

# Live event monitoring
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "What's happening with the California wildfires?"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Config": json.dumps({
            "search_type": "news",
            "time_range": "1h",  # Last hour
            "include_social": True,  # Include social media
            "verify_sources": True,
            "min_source_credibility": 0.8
        })
    }
)

Fact Checking

Verify claims with authoritative sources.

# Fact-check claims
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "Verify: The Great Wall of China is visible from space"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Config": json.dumps({
            "mode": "fact_check",
            "sources": [
                "snopes.com",
                "factcheck.org",
                "politifact.com",
                "nasa.gov",
                "scientificamerican.com"
            ],
            "require_multiple_sources": True,
            "min_sources": 3,
            "include_credibility_scores": True
        })
    }
)

# Research with citations
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "Write a paragraph about climate change impacts with citations"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Citation-Format": "academic",  # [1], [2] style
        "X-Citation-Style": "APA",
        "X-Min-Source-Quality": "high"
    }
)

Search Strategies

Configure how the AI uses web search results:

Search Integration Modespython
# RAG (Retrieval-Augmented Generation) mode
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "Explain the latest developments in renewable energy"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Mode": "rag",
        "X-RAG-Config": json.dumps({
            "chunk_size": 500,
            "overlap": 50,
            "rerank": True,
            "diversity_boost": 0.3,
            "include_snippets": True
        })
    }
)

# Augmented mode - search enriches AI knowledge
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "Compare iPhone 15 Pro with Samsung Galaxy S24"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Mode": "augment",
        "X-Augment-Config": json.dumps({
            "blend_sources": True,
            "prefer_recent": True,
            "fact_weight": 0.8,  # Prioritize facts from search
            "synthesis_mode": "balanced"
        })
    }
)

# Verify mode - check AI responses against web
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "The Eiffel Tower is 324 meters tall"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Mode": "verify",
        "X-Verify-Config": json.dumps({
            "confidence_threshold": 0.9,
            "require_authoritative": True,
            "correct_if_wrong": True
        })
    }
)

Search Filters & Options

Time-Based Filtering

# Search with time constraints
config = {
    "time_range": "custom",
    "date_from": "2024-01-01",
    "date_to": "2024-01-31",
    "prefer_recent": True,
    "boost_fresh_content": 2.0
}

# Predefined ranges
time_options = [
    "hour",    # Last hour
    "day",     # Last 24 hours  
    "week",    # Last 7 days
    "month",   # Last 30 days
    "year",    # Last year
    "custom"   # Specific dates
]

Geographic Filtering

# Region-specific search
config = {
    "regions": ["US", "CA", "UK"],
    "languages": ["en", "fr"],
    "local_results": True,
    "user_location": {
        "lat": 37.7749,
        "lon": -122.4194
    },
    "radius_km": 50
}

Content Type Filters

# Filter by content type
config = {
    "file_types": ["pdf", "html"],
    "exclude_types": ["video", "image"],
    "content_length": {
        "min": 500,   # words
        "max": 10000
    },
    "reading_level": "college"
}

Quality Filters

# Quality and credibility filters
config = {
    "min_domain_authority": 50,
    "require_https": True,
    "exclude_ads": True,
    "exclude_paywalls": True,
    "fact_check_sources": True,
    "peer_reviewed_only": False
}

Search Analytics

Monitor and optimize your web search usage:

Search Metricspython
import requests

# Get search analytics
analytics = requests.get(
    "https://api.parrotrouter.com/v1/search/analytics",
    headers={"Authorization": "Bearer your-api-key"},
    params={
        "start_date": "2024-01-01",
        "end_date": "2024-01-31"
    }
).json()

print(f"Total searches: {analytics['total_searches']}")
print(f"Avg results per search: {analytics['avg_results']}")
print(f"Cache hit rate: {analytics['cache_hit_rate']}%")
print(f"Avg search latency: {analytics['avg_latency_ms']}ms")

# Top search queries
print("
Top Search Topics:")
for topic in analytics['top_topics']:
    print(f"- {topic['query']}: {topic['count']} searches")

# Search quality metrics
print(f"
Search Quality:")
print(f"Relevance score: {analytics['avg_relevance_score']}/10")
print(f"User satisfaction: {analytics['satisfaction_rate']}%")
print(f"Citation accuracy: {analytics['citation_accuracy']}%")

# Cost analysis
print(f"
Search Costs:")
print(f"Total cost: $" + str(analytics['total_cost']))
print(f"Cost per search: $" + str(analytics['cost_per_search']))
print(f"Cached searches saved: $" + str(analytics['cache_savings']))

Use Cases

Research Assistant

# Academic research assistant
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "system",
        "content": "You are an academic research assistant. Always cite sources."
    }, {
        "role": "user",
        "content": "Write a literature review on machine learning in healthcare"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Config": json.dumps({
            "search_type": "academic",
            "min_year": 2020,
            "require_doi": True,
            "citation_format": "APA",
            "max_results": 20
        })
    }
)

News Aggregator

# Real-time news summary
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "Summarize today's top tech news"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Config": json.dumps({
            "search_type": "news",
            "categories": ["technology", "startups", "AI"],
            "time_range": "24h",
            "group_by_topic": True,
            "sentiment_analysis": True
        })
    }
)

Market Intelligence

# Competitor analysis
response = client.chat.completions.create(
    model="gpt-4-turbo-preview",
    messages=[{
        "role": "user",
        "content": "Analyze recent activities of major cloud providers"
    }],
    extra_headers={
        "X-Web-Search": "true",
        "X-Search-Config": json.dumps({
            "companies": ["AWS", "Azure", "Google Cloud"],
            "search_types": ["news", "press_releases", "blog_posts"],
            "time_range": "month",
            "include_financial": True,
            "track_mentions": True
        })
    }
)

Best Practices

  • 1.
    Cache Frequent Searches

    Enable caching for common queries to reduce latency and costs

  • 2.
    Use Specific Domains

    Target authoritative sources for better quality results

  • 3.
    Set Time Ranges

    Limit searches to relevant time periods for current information

  • 4.
    Verify Critical Information

    Use multiple sources for fact-checking important claims

Related Features