ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Build a Research Assistant Without Token Overflow
Tutorial

How to Build a Research Assistant Without Token Overflow

Build a research assistant whose search context fits in the LLM window. Structured snippets, no raw HTML, no manual cleaning.

Get Free API KeyAPI Docs

An r/n8n thread complained that search APIs return raw HTML breaking token limits or strip too much context. This tutorial walks the middle path: structured snippets via Scavio, full-page extracts only for the top 1-2 hits.

Prerequisites

  • Python 3.10+
  • Scavio API key

Walkthrough

Step 1: Search returns 10 typed snippets

Each snippet fits in ~100 tokens.

Python
import requests, os
API_KEY = os.environ['SCAVIO_API_KEY']

def snippets(q):
    r = requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': API_KEY}, json={'query': q}).json()
    return r.get('organic_results', [])[:10]

Step 2: LLM picks top 1-2 to read fully

Cheaper than fetching all 10.

Python
import anthropic
client = anthropic.Anthropic()

def pick(q, snips):
    msg = client.messages.create(model='claude-sonnet-4-6', max_tokens=200,
        messages=[{'role':'user','content':f'Q: {q}. SNIPPETS: {snips}. Return indices of the top 2 to read fully.'}])
    return msg.content[0].text

Step 3: Extract those pages as markdown

Markdown is cheaper tokens than HTML.

Python
def fetch(url):
    r = requests.post('https://api.scavio.dev/api/v1/extract',
        headers={'x-api-key': API_KEY}, json={'url': url, 'format': 'markdown'}).json()
    return r.get('markdown', '')[:5000]  # token-budget the page

Step 4: Compose final answer

Snippets give breadth, full pages give depth.

Python
def answer(q):
    snips = snippets(q)
    picks = [int(i) for i in pick(q, snips).split(',') if i.strip().isdigit()]
    deep = [fetch(snips[i]['link']) for i in picks[:2]]
    return {'snippets': snips, 'deep_reads': deep}

Step 5: Token math

10 snippets ≈ 1K tokens; 2 trimmed pages ≈ 8K tokens; total context ≈ 9K tokens — fits in any 200K-context model.

Text
// Token budget: well under 16K even for a 32K-context model.

Python Example

Python
# Per question: 1 search + 2 extracts = 3 credits = $0.013. Plus LLM token cost.

JavaScript Example

JavaScript
// Same pattern in TS.

Expected Output

JSON
Per question, the agent has 10 snippets and 2 full reads in its context. No raw HTML, no manual cleaning, no token overflow.

Related Tutorials

  • How to Add Structured Search to an AI Assistant

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.10+. Scavio 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 the raw REST API, but you can adapt to your framework of choice.

Related Resources

Best Of

Best Search API for Deep Research Agents in 2026

Read more
Use Case

Hermes Agent Search API Reliability

Read more
Best Of

Best Token-Efficient Search APIs in 2026

Read more
Use Case

MCP Search Gateway for Multi-Agent Systems

Read more
Workflow

Agent Search Cost and Budget Tracking Workflow

Read more
Glossary

Search API Cost per Context Window

Read more

Start Building

Build a research assistant whose search context fits in the LLM window. Structured snippets, no raw HTML, no manual cleaning.

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