Skip to main content
Best for: building Valyu into your product / agents. Add real-time search to a Claude app via Valyu’s Anthropic provider.
The AnthropicProvider exposes Valyu search as a tool to Claude, so your agents can pull real-time information from academic papers, news, financial data, and authoritative sources.

Paste into your AI assistant to wire Valyu search into an Anthropic Claude app.

Open in Cursor

Installation

Install the Valyu and Anthropic packages:
pip install valyu anthropic
Set your API keys as environment variables:
export VALYU_API_KEY="your-valyu-api-key"
export ANTHROPIC_API_KEY="your-anthropic-api-key"

Free Credits

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

Basic Usage

The Anthropic provider handles the integration:
from anthropic import Anthropic
from valyu import AnthropicProvider
from dotenv import load_dotenv

load_dotenv()

# Initialize clients
anthropic_client = Anthropic()
provider = AnthropicProvider()

# Get Valyu tools
tools = provider.get_tools()

# Create a research request
messages = [
    {
        "role": "user",
        "content": "What are the latest developments in quantum computing? Write a summary of your findings."
    }
]

# Step 1: Call Anthropic with tools
response = anthropic_client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1000,
    tools=tools,
    messages=messages,
)

# Step 2: Execute tool calls
tool_results = provider.handle_tool_calls(response=response)

# Step 3: Get final response with search results
if tool_results:
    updated_messages = provider.build_conversation(messages, response, tool_results)
    final_response = anthropic_client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=2000,
        messages=updated_messages,
    )
    
    # Extract and print the response
    for content in final_response.content:
        if hasattr(content, "text"):
            print(content.text)
else:
    for content in response.content:
        if hasattr(content, "text"):
            print(content.text)

How it works

The AnthropicProvider handles tool registration, execution, and conversation flow for you - no manual function definitions or tool-calling logic. Claude decides when to search; the provider runs the call and feeds results back into the conversation.
Claude chooses these per query based on context:
  • max_num_results - 1-20 for standard keys, up to 100 with a special API key
  • included_sources / excluded_sources - target or exclude datasets
  • category - guide search to a topic
  • start_date / end_date - time-bounded searches
  • relevance_threshold - filter by relevance (0-1)
Steer behaviour with a system prompt. Tell Claude to cite sources and to use natural-language queries, not search operators. See the Prompting Guide.
class AnthropicProvider:
    def __init__(self, valyu_api_key: Optional[str] = None): ...
    def get_tools(self) -> List[Dict]: ...
    def handle_tool_calls(self, response, modifiers=None) -> List[Dict]: ...
    def build_conversation(self, input_messages, response, tool_results) -> List[Dict]: ...

Additional Resources

Anthropic API Docs

Official Anthropic Claude documentation

Valyu API Reference

Complete Valyu API documentation

Python SDK

Full Python SDK documentation

Get API Key

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