ScavioScavio
Pricing
Tools
Sign InsGet Startedg
  1. Home
  2. Tutorials
  3. How to Ground an LLM with GitHub Repo Data
Tutorial

How to Ground an LLM with GitHub Repo Data

Ground LLM answers in actual repo content by combining GitHub search via SERP site operators with Scavio's Extract endpoint. With Python and JavaScript code.

Get Free API KeyAPI Docs

Grounding LLM answers in source code beats hallucinated explanations. This tutorial uses Scavio's SERP with site:github.com plus its Extract endpoint to bring repo content into the agent loop without a heavy GitHub API integration. Extract (POST /api/v1/extract) reads a raw file URL and returns it as plain text for 1 credit.

API Docs: Extract API

Prerequisites

  • Python 3.10+
  • A Scavio API key
  • An LLM API key

Walkthrough

Step 1: Search inside a repo via SERP

site:github.com/ORG/REPO scoped search finds the right file fast.

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

def repo_search(repo, query):
    r = requests.post('https://api.scavio.dev/api/v2/google',
        headers={'Authorization': f'Bearer {API_KEY}'},
        json={'query': f'site:github.com/{repo} {query}'})
    return r.json().get('organic_results', [])

Step 2: Fetch the selected file

GitHub raw URLs work with Scavio's Extract endpoint.

Python

# Scavio Extract reads one URL and returns the page as markdown, html or text.
# mode: "normal" (1 credit), "advanced" renders JavaScript (1 credit),
# "ultra" for the hardest pages (2 credits). Only a successful call is billed.
# Docs: https://scavio.dev/docs/extract
def scavio_extract(url, headers, mode="normal", fmt="markdown"):
    r = requests.post("https://api.scavio.dev/api/v1/extract", headers=headers,
                      json={"url": url, "format": fmt, "mode": mode}, timeout=90)
    r.raise_for_status()
    return r.json()["data"]["content"]

def fetch_raw(url):
    raw = url.replace('github.com', 'raw.githubusercontent.com').replace('/blob/', '/')
    return scavio_extract(raw, {'Authorization': f'Bearer {API_KEY}'}, fmt='text')

Step 3: Ground the answer

Pass the fetched content into the LLM prompt with source citation.

Python
import anthropic
client = anthropic.Anthropic()

def grounded_answer(repo, question):
    hits = repo_search(repo, question)
    content = fetch_raw(hits[0]['link']) if hits else ''
    msg = client.messages.create(
        model='claude-sonnet-4-6',
        max_tokens=1024,
        messages=[{'role': 'user', 'content': f'{question}\n\nCONTEXT:\n{content[:4000]}'}])
    return msg.content[0].text

Step 4: Add multi-file composition

Pull top 3 results, rank by relevance, compose context.

Python
def multi_file_context(repo, question):
    hits = repo_search(repo, question)[:3]
    return '\n\n'.join([fetch_raw(h['link'])[:2000] for h in hits])

Step 5: Validate citations

Ensure the LLM response mentions at least one source URL.

Python
def has_citations(answer, urls):
    return any(u in answer for u in urls)

Python Example

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

def repo_grounded(repo, question):
    r = requests.post('https://api.scavio.dev/api/v2/google',
        headers={'Authorization': f'Bearer {API_KEY}'},
        json={'query': f'site:github.com/{repo} {question}'})
    return r.json().get('organic_results', [])[:3]

print(repo_grounded('prisma/prisma', 'migrate.ts'))

JavaScript Example

JavaScript
const API_KEY = process.env.SCAVIO_API_KEY;
export async function repoGrounded(repo, question) {
  const r = await fetch('https://api.scavio.dev/api/v2/google', {
    method: 'POST',
    headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({ query: `site:github.com/${repo} ${question}` })
  });
  return ((await r.json()).organic_results || []).slice(0, 3);
}

Expected Output

JSON
LLM answers cite exact files and code paths in the target repo. Hallucination rate drops materially versus ungrounded answers.

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+. A Scavio API key. An LLM 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 APIs for Open-Source LLM Grounding in 2026

    Read more
    Best Of

    Best Search APIs for Local LLM Web Grounding in 2026

    Read more
    Workflow

    Daily Search Grounding for Ollama Assistant

    Read more
    Comparison

    Hermes Desktop Agent vs Pi Coding Agent

    Read more
    Glossary

    Domain-Specific Agent Harness

    Read more
    Comparison

    Perplexity Sonar API vs Scavio

    Read more

    Start Building

    Ground LLM answers in actual repo content by combining GitHub search via SERP site operators with Scavio's Extract endpoint. With Python and JavaScript code.

    Get Free API KeyRead the Docs
    ScavioScavio

    One scraper API for every social, search, e-commerce and real estate platform. Built for AI agents.

    Product

    • Features
    • Pricing
    • Dashboard
    • Affiliates

    Developers

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

    Alternatives

    • Tavily Alternative
    • SerpAPI Alternative
    • Firecrawl Alternative
    • Exa Alternative
    • Serper Alternative
    • Tavily vs Scavio
    • SerpAPI vs Scavio
    • All alternatives
    • Compare Scavio vs alternatives

    Search APIs

    • Google Search API
    • Amazon Product API
    • YouTube API
    • Reddit API
    • Walmart Product API
    • TikTok API
    • Instagram API

    Tools

    • All Tools

    © 2026 Scavio. All rights reserved.

    Featured on TAAFT
    Terms of ServicePrivacy Policy