The Valyu SDK provides access to the following features:

1. Deep Search - Search and retrieve relevant content from proprietary and public sources

2. Feedback - Submit feedback on search results using transaction IDs

Getting Started

Install the Valyu SDK

pip install valyu

And then instantiate the Valyu client - you can obtain your API key here ($10 free credits cus we are legends)

from valyu import Valyu

# The SDK will automatically use VALYU_API_KEY from environment
valyu = Valyu()

# Alternatively, you can still pass it explicitly
valyu = Valyu(api_key="your-api-key-here")

Quick Start

Let’s see how to use the context search feature with a simple example:

main.py
from valyu import Valyu

# Initialize the client
valyu = Valyu()

# Search for context about a specific topic
response = valyu.context(
    query="What are the benefits of renewable energy?",
    search_type="all",            # Search both proprietary and web sources
    max_num_results=5,            # Limit to top 5 results
    similarity_threshold=0.5,     # Only return results with >50% relevance
    query_rewrite=True,           # Enable query optimization
    max_price=10                  # Maximum price per thousand queries (CPM)
)

# Process the results
print(response)

Input Parameters:

ParameterTypeDescriptionDefault
querystrThe input query to be processed.Required
search_typeLiteral[‘all’, ‘proprietary’, ‘web’]Specifies the type of search to be performed. ‘all’ includes both proprietary and web sources, ‘proprietary’ searches over Valyu indices, and ‘web’ is just web search.”all”
max_num_resultsintThe maximum number of results to be returned.10
similarity_thresholdfloatThe minimum similarity required for a result to be included.0.5
query_rewriteboolEnables or disables query optimisation.True
max_pricefloatMaximum price per thousand queries (CPM).Required

Example Response:

{
    "success": True,
    "error": "",
    "tx_id": "tx_4cce8eed-7864-42ec-b385-dee7d5b14936",
    "query": "What are agentic search-enhanced large reasoning models?",
    "results": [
        {
            "title": "2501.05366",
            "url": "https://arxiv.org/abs/2501.05366",
            "content": "# Search-o1: Agentic Search-Enhanced Large Reasoning Models...",
            "source": "valyu/valyu-arxiv",
            "price": 0.0005,
            "length": 17442,
            "image_url": {
                "_page_1_Figure_0.jpeg": "https://..."
            },
            "data_type": "unstructured",
            "relevance_score": 0.77734375
        }
        // Additional results...
    ],
    "results_by_source": {
        "web": 1,
        "proprietary": 4
    },
    "total_deduction_pcm": 5.0,
    "total_deduction_dollars": 0.005,
    "total_characters": 81208
}

Output Parameters:

ParameterTypeDescription
successbooleanIndicates if the request was successful
errorstringError message if any
tx_idstringUnique transaction ID for the request
querystringThe processed query string
resultsarrayArray of result objects (see Results Object table below)
results_by_sourceobjectCount of results by source type (web/proprietary)
total_deduction_pcmfloatEstimated CPM cost (cost per 1000 queries)
total_deduction_dollarsfloatTotal cost in USD
total_charactersintegerTotal number of characters in results

Results Object:

ParameterTypeDescription
titlestringTitle of the result
urlstringURL of the source
contentstringThe actual text chunk of the result
sourcestringSource identifier, either proprietary or web
pricefloatCost of this specific text chunk in USD
lengthintegerCharacter length of the content
image_urlobjectMap of image identifiers to image URLs, can be used to render in frontend AI applications
data_typestringType of data, either “unstructured” or “structured”. If structured (e.g. for stock data) it will be a string JSON object
relevance_scorefloatRelevance score between 0 and 1