The Real Problem
Exposing a private document collection or Retrieval-Augmented Generation (RAG) system incurs embedding, vector search, and LLM synthesis costs per question. Offering RAG queries for free leads to API budget exhaustion.
Real-World Example: For example, a legal knowledge base or RAG service could charge $0.05 per question query against its private corpus.
How aipp Solves It
Protect your RAG query endpoint with aipp L402 middleware. The user or requesting LLM submits a question, receives a 402 challenge for the set price, pays, and receives the retrieved answer with citations.
Step-by-Step Payment Flow
STEP 01
Submit Question
Client submits question to RAG endpoint.
STEP 02
Query Fee 402
Server issues HTTP 402 challenge for query fee.
STEP 03
Payment Settlement
Client wallet settles invoice.
STEP 04
RAG Answer Delivered
Server verifies payment proof, executes vector retrieval, and returns answer.
Scope & Boundaries
What aipp Does
- ✓ Gates RAG queries and knowledge base lookups behind verified micropayments
- ✓ Verifies payment preimages before allowing protected access
- ✓ Auto-forwards net proceeds to developer wallet
What aipp Does Not Do
- ✗ Does not host vector databases, perform embeddings, or host private documents
- ✗ Does not build RAG retrieval pipelines
- ✗ Does not store document collections
Implementation Pattern
Below is the minimal implementation pattern using standard aipp endpoints / SDK:
app.post('/api/rag/query', l402Paywall({
client: aipp,
amountUsd: 0.05
}), async (req, res) => {
const answer = await ragPipeline.query(req.body.question);
res.json({ answer });
});
Settlement Architecture Note:
• Lightning Rail: In hosted Lightning flows, payments route through aipp's Lightning gateway before net proceeds are automatically forwarded to your configured wallet address.
• Base USDC Rail: USDC transfers settle directly on-chain to your designated EVM wallet address.
• No Merchant Spending Balance: aipp does not maintain a spendable merchant balance or require manual withdrawal steps.
Requirements & Limitations
- Merchant operates the vector database and RAG pipeline
- Funds auto-forward to merchant wallet according to threshold settings
Frequently Asked Questions
Can AI agents query my RAG system automatically?
Yes. Autonomous agents can parse the L402 402 challenge, pay the Lightning invoice, and consume answers programmatically.
Related Use Cases
Gate Paid Document & RAG Query Queries with aipp
Require payment verification before executing data queries or research synthesis.
Open Studio Console →