ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Build a RAG Pipeline with Citations Using Scavio
Tutorial

How to Build a RAG Pipeline with Citations Using Scavio

Build a RAG pipeline that emits citations the user can click. Scavio's typed JSON makes the citation step deterministic.

Get Free API KeyAPI Docs

RAG citations fail when the LLM cannot tie a claim back to a source URL. Scavio's typed JSON gives every retrieved snippet a link field, making the citation step deterministic. This tutorial walks the build.

Prerequisites

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

Walkthrough

Step 1: Retrieve candidates

Scavio /search for the question.

Python
import os, requests
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}

def retrieve(q, n=8):
    r = requests.post('https://api.scavio.dev/api/v1/search', headers=H, json={'query': q}).json()
    return r.get('organic_results', [])[:n]

Step 2: Build a numbered source list

Each source has an index.

Python
def sources(results):
    return [(i, r['link'], r.get('snippet', '')) for i, r in enumerate(results, start=1)]

Step 3: Prompt the LLM with cite markers

Strict instruction.

Text
# Prompt:
# 'Answer the question using ONLY the provided sources.
#  Every claim must be followed by [N] where N is the source index.
#  Sources:
#  [1] {url}: {snippet}
#  [2] {url}: {snippet}
#  ...'

Step 4: Validate citation markers

Regex check before showing user.

Python
import re

def validate(answer, n_sources):
    cites = set(int(m) for m in re.findall(r'\[(\d+)\]', answer))
    return cites and max(cites) <= n_sources

Step 5: Render answer with linked citations

[1] becomes a clickable link.

Python
def render(answer, sources):
    out = answer
    for i, url, _ in sources:
        out = out.replace(f'[{i}]', f'[[{i}]]({url})')
    return out

Python Example

Python
# Per query: 1 Scavio call + 1 LLM call. Cost ~$0.005-0.02 depending on LLM.

JavaScript Example

JavaScript
// Same in TS.

Expected Output

JSON
User-facing answer with clickable citations. Each citation links to the original source, satisfying RAG trust requirements.

Related Tutorials

  • How to Add Real-Time Search to Claude via MCP

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. 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 RAG with Citations in 2026

Read more
Use Case

RAG with Citations Pipeline

Read more
Comparison

Perplexity Sonar API vs Scavio

Read more
Workflow

RAG Corpus Build Workflow (10M Tokens)

Read more
Comparison

Scavio vs Tavily

Read more
Best Of

Best Tools for LLM Wiki-Style RAG Stacks in 2026

Read more

Start Building

Build a RAG pipeline that emits citations the user can click. Scavio's typed JSON makes the citation step deterministic.

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