ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Build Genkit Search Agent with Scavio
Tutorial

How to Build Genkit Search Agent with Scavio

Build a Firebase Genkit agent with web search using Scavio API. Tool definition, flow setup, and TypeScript implementation.

Get Free API KeyAPI Docs

Firebase Genkit provides a structured way to build AI flows with tools. Adding Scavio search as a Genkit tool gives your flows live web access for grounding, research, and data enrichment. This tutorial defines the tool, creates a search flow, and tests it end-to-end in TypeScript.

Prerequisites

  • Node.js 18+
  • Firebase Genkit installed
  • A Scavio API key from scavio.dev
  • TypeScript project setup

Walkthrough

Step 1: Define the Scavio search tool for Genkit

Create a typed Genkit tool definition for web search.

Python
import os, requests, json

# Python equivalent of the TypeScript Genkit tool
# (Genkit is TypeScript-first, but the API call is the same)

API_KEY = os.environ['SCAVIO_API_KEY']
SH = {'x-api-key': API_KEY, 'Content-Type': 'application/json'}

# Genkit tool schema (for reference when writing TypeScript)
genkit_tool_schema = {
    'name': 'webSearch',
    'description': 'Search the web for current information. Returns structured results.',
    'inputSchema': {
        'type': 'object',
        'properties': {
            'query': {'type': 'string', 'description': 'Search query'},
            'platform': {'type': 'string', 'enum': ['google', 'reddit', 'youtube', 'amazon'],
                         'description': 'Platform to search'}
        },
        'required': ['query']
    },
    'outputSchema': {
        'type': 'array',
        'items': {
            'type': 'object',
            'properties': {
                'title': {'type': 'string'},
                'link': {'type': 'string'},
                'snippet': {'type': 'string'}
            }
        }
    }
}

print('Genkit tool schema (TypeScript reference):')
print(json.dumps(genkit_tool_schema, indent=2))

Step 2: Implement the search function

Build the actual search function that the Genkit tool calls.

Python
def genkit_web_search(query, platform=None):
    """Implementation matching the Genkit tool schema."""
    body = {'query': query, 'country_code': 'us'}
    if platform and platform != 'google':
        body['platform'] = platform
    data = requests.post('https://api.scavio.dev/api/v1/search',
        headers=SH, json=body).json()
    return [{'title': r.get('title', ''), 'link': r.get('link', ''),
             'snippet': r.get('snippet', '')} for r in data.get('organic_results', [])[:5]]

# TypeScript equivalent:
ts_code = """
// genkit-search-tool.ts
import { defineTool } from '@genkit-ai/ai';
import { z } from 'zod';

export const webSearch = defineTool(
  {
    name: 'webSearch',
    description: 'Search the web for current information',
    inputSchema: z.object({
      query: z.string().describe('Search query'),
      platform: z.enum(['google', 'reddit', 'youtube', 'amazon']).optional()
    }),
    outputSchema: z.array(z.object({
      title: z.string(),
      link: z.string(),
      snippet: z.string()
    }))
  },
  async ({ query, platform }) => {
    const body = { query, country_code: 'us', ...(platform && { platform }) };
    const resp = await fetch('https://api.scavio.dev/api/v1/search', {
      method: 'POST',
      headers: { 'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json' },
      body: JSON.stringify(body)
    });
    const data = await resp.json();
    return (data.organic_results || []).slice(0, 5).map(r => ({
      title: r.title || '', link: r.link || '', snippet: r.snippet || ''
    }));
  }
);
"""
print(ts_code)

# Test the Python version
results = genkit_web_search('genkit firebase tutorial 2026')
print(f'Test: {len(results)} results')
for r in results[:2]:
    print(f'  {r["title"]}')

Step 3: Create a Genkit flow with search

Wire the search tool into a complete Genkit research flow.

Python
def simulate_genkit_flow(topic):
    """Simulate a Genkit flow that uses search for research."""
    print(f'\n=== Genkit Flow: Research "{topic}" ===')
    # Step 1: Search for overview
    overview = genkit_web_search(f'{topic} overview 2026')
    print(f'  [1] Overview search: {len(overview)} results')
    # Step 2: Search for comparisons
    comparisons = genkit_web_search(f'{topic} vs alternatives comparison')
    print(f'  [2] Comparison search: {len(comparisons)} results')
    # Step 3: Search Reddit for opinions
    opinions = genkit_web_search(f'{topic} review', platform='reddit')
    print(f'  [3] Reddit opinions: {len(opinions)} results')
    # Compile results
    all_sources = overview + comparisons + opinions
    print(f'\n  Total sources: {len(all_sources)}')
    print(f'  Cost: ${3 * 0.005:.3f} (3 search calls)')
    print(f'\n  Top findings:')
    for s in all_sources[:5]:
        print(f'    - {s["title"][:55]}')
    return all_sources

simulate_genkit_flow('Firebase Genkit')
simulate_genkit_flow('Vercel AI SDK')

Python Example

Python
import os, requests
SH = {'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'}

def genkit_search(query, platform=None):
    body = {'query': query, 'country_code': 'us'}
    if platform: body['platform'] = platform
    data = requests.post('https://api.scavio.dev/api/v1/search', headers=SH, json=body).json()
    return data.get('organic_results', [])[:5]

results = genkit_search('genkit search tool 2026')
for r in results:
    print(f'{r["title"]}: {r.get("link", "")}')
print('Cost: $0.005')

JavaScript Example

JavaScript
const SH = { 'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json' };
async function genkitSearch(query, platform) {
  const body = { query, country_code: 'us', ...(platform && { platform }) };
  const data = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST', headers: SH, body: JSON.stringify(body)
  }).then(r => r.json());
  return (data.organic_results || []).slice(0, 5);
}
const results = await genkitSearch('genkit tutorial 2026');
results.forEach(r => console.log(r.title));

Expected Output

JSON
Genkit tool schema (TypeScript reference):
{
  "name": "webSearch",
  "description": "Search the web for current information..."
}

Test: 5 results
  Getting Started with Firebase Genkit
  Genkit AI Flows Tutorial 2026

=== Genkit Flow: Research "Firebase Genkit" ===
  [1] Overview search: 5 results
  [2] Comparison search: 5 results
  [3] Reddit opinions: 5 results

  Total sources: 15
  Cost: $0.015 (3 search calls)

Related Tutorials

  • How to Build a LangChain Search Tool with Scavio
  • How to Add Search to a LangGraph Agent
  • How to Add Search Grounding to Any Python 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.

Node.js 18+. Firebase Genkit installed. A Scavio API key from scavio.dev. TypeScript project setup. 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 the raw REST API, but you can adapt to your framework of choice.

Related Resources

Use Case

Firebase Genkit Search Integration

Read more
Use Case

Pi Coding Agent Web Search Integration

Read more
Best Of

Best Search Plugins for Google Genkit (2026)

Read more
Best Of

Best AI Agent Web Search Tools in 2026

Read more
Solution

Add Unified Search to Multi-Agent Systems with Scavio

Read more
Solution

Coding Agent Search Tool Debugging

Read more

Start Building

Build a Firebase Genkit agent with web search using Scavio API. Tool definition, flow setup, and TypeScript implementation.

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