leanrag.prune()

context pruning api

Your RAG app pays for tokens it never needed.

LeanRAG sits between your retriever and your LLM. Send chunks + question, get back the minimal context that answers it — typically 40–70% fewer input tokens, with a running ledger of every dollar saved.

free · 5,000 prunes/mo · no card required

POST /api/v1/prune · "How tall is the Eiffel Tower?"-71% tokens

The Eiffel Tower is located in Paris, France.

It was completed in 1889 as the entrance arch to the World's Fair.

The tower is 330 metres tall.

Millions of tourists visit it every year.

Paris is known for its cafes, museums, and fashion industry.

The Louvre, located in Paris, is the world's largest art museum.

Reinforced concrete became popular in the twentieth century.

Skyscrapers in New York pushed engineering limits.

tokens: 118 → 34 · saved $0.00021 this call

01

Drop-in, one call

POST your retrieved chunks + the user question. Get back only the sentences the answer needs, in original order. No SDK, no re-architecture — it slots between your retriever and your LLM.

02

Savings you can screenshot

Every response carries tokens_in, tokens_out and cost_saved_usd at your model's real price. The dashboard totals it: “you saved $312 this month.” Show that to whoever pays the API bill.

03

Deterministic & fast

Extractive pruning — no LLM in the loop, so nothing is hallucinated into your context, latency stays under ~50ms, and your data is never sent to a model provider.

Try it on your own chunks

Paste real retrieval output from your app. No signup needed for the demo.

→ run prune() to see what your LLM actually needs

Quickstart — 2 minutes

One endpoint. Auth with your key, send question + chunks, feed the returned context to your LLM.

curl -s https://leanrag.aiskillhub.info/api/v1/prune \
  -H "Authorization: Bearer $LEANRAG_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "question": "What discount do annual plans get?",
    "chunks": ["...retrieved chunk 1...", "...chunk 2..."],
    "model": "gpt-4o",
    "aggressiveness": "balanced"
  }'

request options

  • aggressiveness — conservative | balanced | aggressive
  • budget_tokens — hard cap on returned context
  • model — for $ savings (gpt-4o, claude-sonnet, …)
  • price_per_mtok — override with your contract price

response

  • context — pruned text, original order preserved
  • tokens_in / tokens_out / tokens_saved
  • cost_saved_usd — this call's savings
  • usage_this_month — against your plan limit

Also: POST /api/v1/rotate-key (auth with current key) and GET /api/v1/usage.

Priced far below what it saves you

A RAG app doing 100k calls/month at ~2k context tokens each spends ~$500/mo on input tokens at GPT-4o prices. Cutting 50% saves $250/mo. Starter costs $19.

Free

Prove the savings

$0 /mo
  • 5,000 prunes / month
  • All aggressiveness modes
  • Token + $ savings on every response
  • Community support
Get free API key

Starter

most popular

For production RAG apps

$19 /mo
  • 100,000 prunes / month
  • Usage dashboard
  • Monthly savings report
  • Email support
Reserve Starter

Pro

For teams bleeding tokens

$49 /mo
  • Unlimited prunes
  • Analytics dashboard + savings ledger
  • Priority support
  • Custom price-per-token config
Reserve Pro

Card + UPI checkout launching this week — reserving a paid plan locks this price for 12 months.

Questions devs ask

Won't pruning hurt answer quality?

We measured it on HotpotQA distractor — deliberately the hardest public setting for pruning (multi-hop, 8 of 10 paragraphs are distractors). Balanced mode cut 55.5% of tokens while keeping 87.5% of answers reachable; conservative cut 35.3% keeping 95.3%. Full methodology on the benchmark page. Your single-hop docs corpus will do better. You control the dial per call.

How is this different from just lowering top-k?

Lowering top-k drops whole chunks and loses answers that live in chunk #7. LeanRAG works inside chunks at sentence level — chunk #7's one relevant sentence survives while the boilerplate around it goes.

Does my data get sent to an LLM?

No. Pruning is deterministic and runs entirely on our servers with no third-party model calls. Chunks are processed in memory and only aggregate token counts are stored.

What tokenizer do you count with?

o200k_base (GPT-4o family). Dollar savings use a per-model price table, or pass price_per_mtok to match your exact contract pricing.