Skip to main content

Overview

Best for: building Valyu into your product / agents. Use Valyu as a search and content tool inside LangChain (TypeScript) agents.
Viewing the TypeScript integration. For the Python version of this guide, see the Python LangChain integration.
Valyu integrates seamlessly with LangChain as a search tool, allowing you to enhance your AI agents and RAG applications with real-time web search and proprietary data sources. The integration provides LLM-ready context from multiple sources including web pages, academic journals, financial data, and more. The package includes two main tools:
  • ValyuSearchTool: Search operations with comprehensive parameter control
  • ValyuContentsTool: Extract clean content from specific URLs

Paste into your AI assistant to wire Valyu into a LangChain (TypeScript) agent.

Open in Cursor

Integration details

ComponentSourcePackage
ValyuSearchToolProprietary + public web content (search)@valyu/langchain
ValyuContentsToolWeb pages (content extraction)@valyu/langchain

Installation

Install the official LangChain Valyu package and the Valyu SDK:
npm install @valyu/langchain valyu-js @langchain/core
yarn add @valyu/langchain valyu-js @langchain/core
pnpm add @valyu/langchain valyu-js @langchain/core
Configure credentials by setting the following environment variable:
process.env.VALYU_API_KEY = "your-valyu-api-key-here";
Or set it programmatically:
import * as dotenv from "dotenv";
dotenv.config();
For agent examples, you’ll also need:
process.env.ANTHROPIC_API_KEY = "your-anthropic-api-key";
process.env.OPENAI_API_KEY = "your-openai-api-key";

Free Credits

Get your API key with $10 free credits ($20 with a work email) from the Valyu Platform.

Basic Usage

import { ValyuSearchTool, ValyuAdapter } from "@valyu/langchain";

const valyuClient = new ValyuAdapter(process.env.VALYU_API_KEY!);

const tool = new ValyuSearchTool({
  client: valyuClient,
});

const searchResults = await tool.invoke({
  query: "What are agentic search-enhanced large reasoning models?",
  search_type: "all", // "all", "web", or "proprietary"
  max_num_results: 5,
  relevance_threshold: 0.5,
  max_price: 30.0,
});

console.log("Search Results:", JSON.parse(searchResults));

Using ValyuContentsTool for Content Extraction

Extract clean, structured content from specific URLs:
import { ValyuContentsTool, ValyuAdapter } from "@valyu/langchain";

const valyuClient = new ValyuAdapter(process.env.VALYU_API_KEY!);

const contentsTool = new ValyuContentsTool({
  client: valyuClient,
});

const urls = [
  "https://arxiv.org/abs/2301.00001",
  "https://example.com/article",
];

const extractedContent = await contentsTool.invoke({ urls });
const results = JSON.parse(extractedContent);

console.log("Extracted Content:", results.results);

for (const result of results.results || []) {
  console.log(`URL: ${result.url}`);
  console.log(`Title: ${result.title}`);
  console.log(`Content: ${result.content?.substring(0, 200)}...`);
  console.log(`Status: ${result.status}`);
  console.log("---");
}

Using with LangChain Agents

The most powerful way to use Valyu is within LangChain agents, where the AI can dynamically decide when and how to search:
npm
npm install @langchain/anthropic @langchain/langgraph
import { ValyuSearchTool, ValyuAdapter } from "@valyu/langchain";
import { ChatAnthropic } from "@langchain/anthropic";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { HumanMessage } from "@langchain/core/messages";

const valyuClient = new ValyuAdapter(process.env.VALYU_API_KEY!);

const llm = new ChatAnthropic({
  model: "claude-sonnet-4-20250514",
  apiKey: process.env.ANTHROPIC_API_KEY,
});

const valyuSearchTool = new ValyuSearchTool({
  client: valyuClient,
});

const agent = createReactAgent({ llm, tools: [valyuSearchTool] });

const userInput =
  "What are the key factors driving recent stock market volatility, and how do macroeconomic indicators influence equity prices across different sectors?";

const stream = await agent.stream({
  messages: [new HumanMessage(userInput)],
});

for await (const step of stream) {
  console.log(step.messages[step.messages.length - 1].content);
}

Advanced configuration

tool.invoke() accepts:
  • query (required) - natural-language query string
  • search_type - "all", "web", or "proprietary" (use "all" when passing included_sources URLs)
  • max_num_results - 1-20 (up to 100 with a special API key)
  • relevance_threshold - 0.0-1.0
  • max_price - max cost per 1k retrievals (CPM)
  • start_date / end_date - YYYY-MM-DD
  • included_sources / excluded_sources - arrays of URLs, domains, or dataset ids
  • response_length - "short", "medium", "large", "max", or a character count
  • country_code - 2-letter ISO code (e.g. "US", "GB")
  • fast_mode - faster but shorter results
The tool returns a JSON string - parse it with JSON.parse().
Invoke with a required urls array (max 10 per request). Constructor options: summary (boolean/string/object), extract_effort ("normal", "high", "auto"), response_length ("short", "medium", "large", "max", or a number).
Bind a SystemMessage: use search_type="all" for broad coverage (web + proprietary), or "web" for current events only; raise relevance_threshold (0.6+) for precision; cite sources; use natural-language queries, not operators. See the Prompting Guide.

Additional Resources

LangChain Valyu Tool

Official LangChain Python integration documentation

API Reference

Complete Valyu API documentation

LangGraph Agents

Build advanced agent workflows

Get API Key

Sign up for $10 free credits ($20 with a work email)