Tutorial

How to Add Structured Search to an AI Assistant

Stop pasting raw HTML into your prompt. Add a typed search call to your AI assistant in 5 minutes with Scavio.

An r/n8n thread asked for a search API that returns structured snippets ready to drop into an LLM context window — not raw HTML, not stripped meaning. This tutorial wires Scavio's /search endpoint into a Python or Node assistant in under 5 minutes.

Prerequisites

  • Python 3.10+ or Node 20+
  • Scavio API key (500 free credits/mo)

Walkthrough

Step 1: Get your API key

Sign up at scavio.dev. The free tier returns 500 credits/mo, no card.

Bash
export SCAVIO_API_KEY=sk_...

Step 2: Make the search call

POST to /api/v1/search with x-api-key header.

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

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

Step 3: Pull only the fields the LLM needs

Title, snippet, link. Drop the rest.

Python
def trim(results):
    return [{'title': r['title'], 'snippet': r['snippet'], 'url': r['link']}
            for r in results.get('organic_results', [])[:5]]

Step 4: Inject into the prompt

Pass trimmed results as part of the system context.

Python
context = '\n'.join(f'- {r["title"]}: {r["snippet"]} ({r["url"]})' for r in trim(search('reddit api alternatives 2026')))
prompt = f'Use this context to answer the question.\n\n{context}\n\nQuestion: which APIs replace Reddit\'s direct search?'

Step 5: Pair with the extract endpoint when more context is needed

Fetch the top result as markdown.

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'})
    return r.json().get('markdown', '')

Python Example

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

def ask_with_search(question):
    s = requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': API_KEY}, json={'query': question}).json()
    ctx = '\n'.join(f'{r["title"]}: {r["snippet"]}' for r in s.get('organic_results', [])[:5])
    return ctx

print(ask_with_search('what is mcp'))

JavaScript Example

JavaScript
const API_KEY = process.env.SCAVIO_API_KEY;
export async function search(q) {
  const r = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST',
    headers: { 'x-api-key': API_KEY, 'Content-Type': 'application/json' },
    body: JSON.stringify({ query: q })
  });
  return r.json();
}

Expected Output

JSON
Five clean snippets per query, ready to inject into the LLM's context. Token cost stays under 800 tokens for the search context block.

Related Tutorials

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+ or Node 20+. Scavio API key (500 free credits/mo). A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, 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.

Start Building

Stop pasting raw HTML into your prompt. Add a typed search call to your AI assistant in 5 minutes with Scavio.