ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Connect Scavio to LangChain RAG
Tutorial

How to Connect Scavio to LangChain RAG

Add Scavio as a LangChain tool in a RAG agent. Configure the tool, connect to an agent chain, and show retrieval plus generation flow with code examples.

Get Free API KeyAPI Docs

You can add Scavio as a LangChain tool by wrapping the search API in a Tool object and passing it to an agent. The agent calls the tool when it needs current information, retrieves the results, and uses them in its final answer.

Prerequisites

  • Python 3.9+
  • langchain, langchain-anthropic packages
  • Scavio API key
  • Anthropic API key

Walkthrough

Step 1: Install dependencies

Install LangChain and the Anthropic integration.

Bash
pip install langchain langchain-anthropic requests

Step 2: Define the Scavio search tool

Wrap the search API call as a LangChain Tool with a clear description.

Python
import requests
from langchain.tools import Tool

SCAVIO_KEY = "your-scavio-api-key"

def scavio_search(query: str) -> str:
    r = requests.post(
        "https://api.scavio.dev/api/v1/search",
        json={"query": query, "num_results": 5},
        headers={"x-api-key": SCAVIO_KEY},
        timeout=15
    )
    r.raise_for_status()
    results = r.json().get("organic_results", [])
    return "\n\n".join(
        f"{r['title']}\n{r.get('snippet','')}\n{r['link']}"
        for r in results[:5]
    ) or "No results found."

search_tool = Tool(
    name="web_search",
    func=scavio_search,
    description="Search the web for current information. Input is a search query string."
)

Step 3: Create the agent with the tool

Use LangChain's create_react_agent or initialize_agent with the search tool.

Python
from langchain_anthropic import ChatAnthropic
from langchain.agents import create_react_agent, AgentExecutor
from langchain.prompts import PromptTemplate

ANTHROPIC_KEY = "your-anthropic-key"

llm = ChatAnthropic(
    model="claude-sonnet-4-6",
    anthropic_api_key=ANTHROPIC_KEY
)

tools = [search_tool]

prompt = PromptTemplate.from_template("""
You are a research assistant. Use the web_search tool to find current information.

Tools: {tools}
Tool names: {tool_names}

Question: {input}
Thought: {agent_scratchpad}
""")

agent = create_react_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True, max_iterations=3)

result = executor.invoke({"input": "What is the current price of Anthropic Claude API?"})
print(result["output"])

Python Example

Python
import requests
from langchain.tools import Tool
from langchain_anthropic import ChatAnthropic
from langchain.agents import create_react_agent, AgentExecutor
from langchain.prompts import PromptTemplate

SCAVIO_KEY = "your-scavio-api-key"
ANTHROPIC_KEY = "your-anthropic-key"

def scavio_search(query: str) -> str:
    r = requests.post(
        "https://api.scavio.dev/api/v1/search",
        json={"query": query, "num_results": 5},
        headers={"x-api-key": SCAVIO_KEY}, timeout=15
    )
    r.raise_for_status()
    items = r.json().get("organic_results", [])
    return "\n\n".join(f"{i['title']}\n{i.get('snippet','')}\n{i['link']}" for i in items[:5]) or "No results."

search_tool = Tool(name="web_search", func=scavio_search,
                   description="Search the web for current information. Input: search query string.")

llm = ChatAnthropic(model="claude-sonnet-4-6", anthropic_api_key=ANTHROPIC_KEY)

prompt = PromptTemplate.from_template("""
Answer questions using the web_search tool for current information.
Tools: {tools}
Tool names: {tool_names}
Question: {input}
{agent_scratchpad}
""")

agent = create_react_agent(llm, [search_tool], prompt)
executor = AgentExecutor(agent=agent, tools=[search_tool], verbose=False, max_iterations=3)

if __name__ == "__main__":
    questions = [
        "What AI models did Anthropic release in 2026?",
        "What is the price of Firecrawl per month?"
    ]
    for q in questions:
        result = executor.invoke({"input": q})
        print(f"Q: {q}")
        print(f"A: {result['output']}\n")

JavaScript Example

JavaScript
// LangChain JS equivalent
import { DynamicTool } from '@langchain/core/tools';
import { ChatAnthropic } from '@langchain/anthropic';
import { AgentExecutor, createReactAgent } from 'langchain/agents';
import { pull } from 'langchain/hub';

const SCAVIO_KEY = 'your-scavio-api-key';

const searchTool = new DynamicTool({
  name: 'web_search',
  description: 'Search the web for current information. Input: search query string.',
  func: async (query) => {
    const res = await fetch('https://api.scavio.dev/api/v1/search', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json', 'x-api-key': SCAVIO_KEY },
      body: JSON.stringify({ query, num_results: 5 })
    });
    const data = await res.json();
    return (data.organic_results ?? [])
      .map(r => `${r.title}\n${r.snippet ?? ''}\n${r.link}`).join('\n\n') || 'No results.';
  }
});

const llm = new ChatAnthropic({ model: 'claude-sonnet-4-6', apiKey: 'your-anthropic-key' });
const prompt = await pull('hwchase17/react');
const agent = await createReactAgent({ llm, tools: [searchTool], prompt });
const executor = new AgentExecutor({ agent, tools: [searchTool], maxIterations: 3 });

const result = await executor.invoke({ input: 'What is the current Anthropic Claude API pricing?' });
console.log(result.output);

Expected Output

JSON
Q: What AI models did Anthropic release in 2026?
A: Based on current search results, Anthropic released Claude 3.7 Sonnet and Claude 4 Opus in 2026. Claude 3.7 Sonnet introduced extended thinking mode with a 200K context window.

Q: What is the price of Firecrawl per month?
A: Firecrawl offers a free tier with 1,000 credits, a Starter plan at $16/month for 5,000 credits, and a Scale plan at $83/month for 100,000 credits (annual billing).

Related Tutorials

  • How to Integrate a Search API with CrewAI
  • How to Set Up RAG with Search Instead of Vectors
  • How to Build a Multi-Source Research Agent

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Python 3.9+. langchain, langchain-anthropic packages. Scavio API key. Anthropic API key. A Scavio API key gives you 50 free credits on signup.

Yes. The free tier includes 50 credits on signup, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses LangChain, but you can adapt to your framework of choice.

Related Resources

Best Of

Best Search APIs for LangChain RAG Pipelines in May 2026

Read more
Use Case

Pi Coding Agent Web Search Integration

Read more
Best Of

Best Search API for LangChain in 2026

Read more
Use Case

Hermes Agent Search API Reliability

Read more
Solution

One Search Tool for Any AI Agent Framework

Read more
Solution

Local RAG with Search API Fallback

Read more

Start Building

Add Scavio as a LangChain tool in a RAG agent. Configure the tool, connect to an agent chain, and show retrieval plus generation flow with code examples.

Get Free API KeyRead the Docs
ScavioScavio

Real-time search API for AI agents. Search every platform, not just Google.

Product

  • Features
  • Pricing
  • Dashboard
  • Affiliates

Developers

  • Documentation
  • API Reference
  • Quickstart
  • MCP Integration
  • Python SDK

Alternatives

  • Tavily Alternative
  • SerpAPI Alternative
  • Firecrawl Alternative
  • Exa Alternative

Tools

  • JSON Formatter
  • cURL to Code
  • Token Counter
  • All Tools

© 2026 Scavio. All rights reserved.

Featured on TAAFT
Terms of ServicePrivacy Policy