Runnable examples for TokenPath — token-level attribution for LLM output. One API call after generation automatically discovers the source-bearing phrases in a model's answer and maps each one back to the exact source span that produced it, measured from model attention. Not "this answer cites this chunk" — these 6 words came from those 9 words.
curl https://api.tokenpath.ai/v1/attributions \
-H "Authorization: Bearer $TOKENPATH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"document": "In Q3, revenue grew 18% year over year.",
"question": "How fast did revenue grow?",
"answer": "Revenue grew 18% year over year."
}'Works with output from any model — nothing about your generation stack
changes. For advanced workflows that need caller-controlled coverage, such as
provenance for every leaf in structured JSON, you can optionally provide exact
answer spans.
| Cookbook | What it shows |
|---|---|
| PDF attribution | Link statements in an answer to the exact supporting text in a PDF, then highlight that text on the original page. Includes a live Adobe earnings demo and an Adobe PDF Extract pipeline for your own files. |
Every recipe here is something we've built and run for real — executed against the live API, outputs included. The collection grows as we ship.
| Notebook | What it shows |
|---|---|
| How TokenPath works | The internals, hands-on: turn the attention heatmap into a citation, three things string matching can't do (cross-lingual, paraphrase, tables), and an optional section that reproduces the same attention read from raw Transformers on Llama-3.1-8B. |
| Citation highlighting | Perplexity-style citations whose highlights land on the exact words, not the chunk. TokenPath automatically selects the answer phrases; the recipe renders them inline and as standalone HTML. |
| Structured output attribution | Trace every extracted JSON field back to its exact source span — including disambiguating repeated values that naive string search maps to the wrong occurrence. |
| Transcript Q&A attribution | Meeting notes and transcript answers where automatically selected phrases link back to the speaker, timestamp, and exact words behind them. |
| Heatmap visualization | The raw answer-token × document-token attention matrix: densify, plot, and roll up. |
Open in Colab: how TokenPath works · citation highlighting · structured output · transcript Q&A · heatmap visualization
Tracked as issues — comment or 👍 to prioritize:
- Cited search agent — the tokenpath.ai search demo, end to end
git clone https://github.com/tokenpath/tokenpath-cookbook.git
cd tokenpath-cookbook
pip install -r requirements.txt
export TOKENPATH_API_KEY=... # free key: https://platform.tokenpath.ai
jupyter lab notebooks/Every notebook needs a TOKENPATH_API_KEY — sign up at
platform.tokenpath.ai for 10M free attributed
tokens, no card required. After that it's $1 per 1M attributed tokens, pay as
you go.
- 🐛 Bugs & broken examples → open an Issue.
Fastest way to get something fixed — include the notebook name and the
request_idfrom any API error. - 💬 "How do I…?" questions → start a Discussion. Integration questions, use-case design, "is TokenPath right for X" — anything that isn't a bug.
- 📚 API reference → docs.tokenpath.ai
- ✉️ Private/billing questions → support@tokenpath.ai
Recipes are welcome. Open an issue describing the use case first (so we can
point you at prior art), then PR a notebook that follows the pattern here:
self-contained, runnable top-to-bottom with only TOKENPATH_API_KEY set, heavy
dependencies behind a guarded cell.