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

npm install valyu
# or
yarn add valyu

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

import { Valyu } from "valyu";

// The SDK will automatically use VALYU_API_KEY from environment
const valyu = new Valyu();

// Alternatively, you can still pass it explicitly
const valyu = new Valyu("your-api-key-here");

Quick Start

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

main.ts
import { Valyu } from "valyu";

// Initialize the client
const valyu = new Valyu();

// Search for context about a specific topic
const response = await valyu.context({
    query: "What are the benefits of renewable energy?",
    searchType: "all",            // Search both proprietary and web sources
    maxNumResults: 5,             // Limit to top 5 results
    similarityThreshold: 0.5,     // Only return results with >50% relevance
    queryRewrite: true,           // Enable query optimization
    maxPrice: 10                  // Maximum price per thousand queries (CPM)
});

// Process the results
console.log(response);

Input Parameters:

ParameterTypeDescriptionDefault
querystringThe 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”
maxNumResultsnumberThe maximum number of results to be returned.10
similarityThresholdnumberThe minimum similarity required for a result to be included.0.5
queryRewritebooleanEnables or disables query optimisation.true
maxPricenumberMaximum 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://..."
            },
            "dataType": "unstructured",
            "relevanceScore": 0.77734375
        }
        // Additional results...
    ],
    "resultsBySource": {
        "web": 1,
        "proprietary": 4
    },
    "totalDeductionPcm": 5.0,
    "totalDeductionDollars": 0.005,
    "totalCharacters": 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)
resultsBySourceobjectCount of results by source type (web/proprietary)
totalDeductionPcmnumberEstimated CPM cost (cost per 1000 queries)
totalDeductionDollarsnumberTotal cost in USD
totalCharactersnumberTotal 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
pricenumberCost of this specific text chunk in USD
lengthnumberCharacter length of the content
image_urlobjectMap of image identifiers to image URLs, can be used to render in frontend AI applications
dataTypestringType of data, either “unstructured” or “structured”. If structured (e.g. for stock data) it will be a string JSON object
relevanceScorenumberRelevance score between 0 and 1

For detailed documentation on each feature, please refer to their respective pages:

- Context Search