Groq's inference engine runs Llama and Mixtral models at 500+ tokens/second, but models running on Groq have the same knowledge cutoff as anywhere else -- they cannot answer questions about events after their training date, check current prices, or verify live facts. The standard solution is retrieval-augmented generation: search the web for current information, then feed the results into the model as context. This tutorial connects Groq's fast inference to Scavio's Google Search API so the model can answer questions grounded in real-time web data. The pattern is three calls: search Google via Scavio (2 credits, ~$0.01), extract the relevant snippets, and pass them to Groq as system context alongside the user's question. Total latency is typically under 2 seconds because Groq's inference is fast enough that the search call is the bottleneck. Scavio returns structured JSON with organic results, knowledge panels, and answer boxes already parsed -- no HTML to clean, no headless browser to run. Groq charges per token on their API. Combined cost for a grounded answer: roughly $0.01 for the search plus $0.001-0.003 for the Groq inference, depending on context length.
Prerequisites
- A Scavio API key from scavio.dev (500 free credits on signup, each Google search costs 2 credits)
- A Groq API key from console.groq.com (free tier available)
- Python 3.10+ with requests and groq packages, or Node.js 18+ for the JS version
Walkthrough
Step 1: Install dependencies
You need the requests library for Scavio API calls and the official groq package for Groq inference. Both are lightweight with no heavy dependencies.
pip install requests groqStep 2: Set up the search function
The Scavio Google endpoint returns structured organic results with title, link, snippet, and position. Each call costs 2 credits ($0.01). The response is already parsed JSON -- no HTML scraping or cleaning needed.
import os
import requests
from groq import Groq
SCAVIO_API_KEY = os.environ["SCAVIO_API_KEY"]
GROQ_API_KEY = os.environ["GROQ_API_KEY"]
def search_web(query: str) -> list[dict]:
"""Search Google via Scavio and return organic results."""
r = requests.post(
"https://api.scavio.dev/api/v1/google",
headers={"Authorization": f"Bearer {SCAVIO_API_KEY}"},
json={"query": query},
timeout=15,
)
r.raise_for_status()
data = r.json()
return data.get("organic_results", [])Step 3: Format search results as LLM context
Take the top 5 organic results and format them as a readable context block. Each entry includes the page title, URL, and Google's snippet. This gives the model enough signal to answer factual questions without hallucinating, while keeping the context window small enough that Groq's inference stays fast.
def build_context(results: list[dict], max_results: int = 5) -> str:
"""Format search results as context for the LLM."""
lines = []
for r in results[:max_results]:
title = r.get("title", "")
snippet = r.get("snippet", "")
link = r.get("link", "")
lines.append(f"[{title}]({link})\n{snippet}")
return "\n\n".join(lines)Step 4: Combine search and inference into one function
The core pattern: search, build context, call Groq. The system prompt instructs the model to answer only from the provided search results and cite sources by title, which reduces hallucination. Temperature is set low (0.1) because factual grounding needs precision, not creativity. Groq runs Llama 4 Scout at 500+ tokens/second, so the model's response arrives in under a second even with a large context.
def ask_with_search(question: str) -> str:
"""Answer a question using web search + Groq inference."""
results = search_web(question)
context = build_context(results)
client = Groq(api_key=GROQ_API_KEY)
chat = client.chat.completions.create(
model="llama-4-scout-17b-16e-instruct",
messages=[
{
"role": "system",
"content": f"Answer the user's question using ONLY the search results below. "
f"Cite sources by title. If the results don't contain the answer, say so.\n\n"
f"Search results:\n{context}",
},
{"role": "user", "content": question},
],
temperature=0.1,
max_tokens=1024,
)
return chat.choices[0].message.content
answer = ask_with_search("What is the current price of the RTX 5090?")
print(answer)Step 5: Scale to a multi-question agent
Wrap the pattern into an agent that processes a batch of questions. Each question gets its own search call and inference pass. At 2 credits per search ($0.01) and Groq's inference cost of roughly $0.001 per answer, a batch of 100 grounded answers costs about $1.10 total. The sources array preserves provenance so downstream consumers can verify claims.
import json
def search_agent(questions: list[str]) -> list[dict]:
"""Process multiple questions with search grounding."""
answers = []
for q in questions:
results = search_web(q)
context = build_context(results)
client = Groq(api_key=GROQ_API_KEY)
chat = client.chat.completions.create(
model="llama-4-scout-17b-16e-instruct",
messages=[
{
"role": "system",
"content": f"Answer using ONLY these search results. Cite sources.\n\n{context}",
},
{"role": "user", "content": q},
],
temperature=0.1,
max_tokens=1024,
)
answers.append({
"question": q,
"answer": chat.choices[0].message.content,
"sources": [r["link"] for r in results[:5]],
})
return answers
results = search_agent([
"Who won the Champions League 2026?",
"Latest Python version released this month?",
"SpaceX Starship last launch date?",
])
print(json.dumps(results, indent=2))Python Example
import os
import requests
from groq import Groq
SCAVIO_API_KEY = os.environ["SCAVIO_API_KEY"]
GROQ_API_KEY = os.environ["GROQ_API_KEY"]
def search_web(query: str) -> list[dict]:
r = requests.post(
"https://api.scavio.dev/api/v1/google",
headers={"Authorization": f"Bearer {SCAVIO_API_KEY}"},
json={"query": query},
timeout=15,
)
r.raise_for_status()
return r.json().get("organic_results", [])
def build_context(results: list[dict], max_results: int = 5) -> str:
lines = []
for r in results[:max_results]:
lines.append(f"[{r.get('title', '')}]({r.get('link', '')})\n{r.get('snippet', '')}")
return "\n\n".join(lines)
def ask_with_search(question: str) -> str:
results = search_web(question)
context = build_context(results)
client = Groq(api_key=GROQ_API_KEY)
chat = client.chat.completions.create(
model="llama-4-scout-17b-16e-instruct",
messages=[
{
"role": "system",
"content": f"Answer using ONLY these search results. Cite sources by title.\n\nSearch results:\n{context}",
},
{"role": "user", "content": question},
],
temperature=0.1,
max_tokens=1024,
)
return chat.choices[0].message.content
print(ask_with_search("What is the current price of the RTX 5090?"))JavaScript Example
const Groq = require("groq-sdk").default;
const SCAVIO_API_KEY = process.env.SCAVIO_API_KEY;
const GROQ_API_KEY = process.env.GROQ_API_KEY;
async function searchWeb(query) {
const r = await fetch("https://api.scavio.dev/api/v1/google", {
method: "POST",
headers: {
Authorization: `Bearer ${SCAVIO_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ query }),
});
const data = await r.json();
return data.organic_results ?? [];
}
function buildContext(results, max = 5) {
return results
.slice(0, max)
.map((r) => `[${r.title}](${r.link})\n${r.snippet ?? ""}`)
.join("\n\n");
}
async function askWithSearch(question) {
const results = await searchWeb(question);
const context = buildContext(results);
const client = new Groq({ apiKey: GROQ_API_KEY });
const chat = await client.chat.completions.create({
model: "llama-4-scout-17b-16e-instruct",
messages: [
{
role: "system",
content: `Answer using ONLY these search results. Cite sources by title.\n\n${context}`,
},
{ role: "user", content: question },
],
temperature: 0.1,
max_tokens: 1024,
});
return chat.choices[0].message.content;
}
const answer = await askWithSearch("What is the current price of the RTX 5090?");
console.log(answer);Expected Output
Based on search results, the NVIDIA RTX 5090 is currently priced at $1,999 MSRP.
According to [Tom's Hardware RTX 5090 Review], the card launched at $1,999 and is
available at major retailers including Best Buy and Newegg, though stock remains
limited. [TechPowerUp GPU Database] confirms the $1,999 MSRP with actual street
prices ranging from $1,999 to $2,299 depending on the AIB partner model.