Cookbook
Cookbook
Answer with sentence-level citations
Search, number every passage by its source, and build a prompt your model can cite.
1 min read · Updated 20 Nov 2026
On this page
Give your model passages it can cite by number, and keep a list that maps each number back to a page. The model answers with [1] and [2], and your interface turns those into links.
cited-prompt.py
import osimport requestsAPI = "https://fluxsearch.io/api/v1"HEADERS = {"Authorization": f"Bearer {os.environ['FLUX_API_KEY']}"}QUESTION = "What did CATL and HyperStrong agree, and when?"response = requests.post( f"{API}/search", headers=HEADERS, json={"query": "CATL HyperStrong sodium-ion supply agreement", "max_results": 5, "enrich": 2}, timeout=120,)response.raise_for_status()passages, sources = [], []for result in response.json()["results"]: if not result["lineage"]: continue sources.append(f"[{len(sources) + 1}] {result['title']}\n {result['url']}") for passage in result["lineage"]["results"]: passages.append(f"[{len(sources)}] {passage['enriched_text'].strip()}")prompt = "\n".join( [ "Answer using only these passages. Cite each claim with its number.", "", *passages, "", f"Question: {QUESTION}", ])print(prompt)print()print("\n".join(sources))const API = "https://fluxsearch.io/api/v1";const QUESTION = "What did CATL and HyperStrong agree, and when?";type Passage = { enriched_text: string };type Result = { title: string; url: string; lineage: { results: Passage[] } | null };const response = await fetch(`${API}/search`, { method: "POST", headers: { Authorization: `Bearer ${process.env.FLUX_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ query: "CATL HyperStrong sodium-ion supply agreement", max_results: 5, enrich: 2, }),});if (!response.ok) throw new Error(`Flux ${response.status}: ${await response.text()}`);const { results } = (await response.json()) as { results: Result[] };const passages: string[] = [];const sources: string[] = [];for (const result of results) { if (!result.lineage) continue; sources.push(`[${sources.length + 1}] ${result.title}\n ${result.url}`); for (const passage of result.lineage.results) { passages.push(`[${sources.length}] ${passage.enriched_text.trim()}`); }}const prompt = [ "Answer using only these passages. Cite each claim with its number.", "", ...passages, "", `Question: ${QUESTION}`,].join("\n");console.log(prompt);console.log();console.log(sources.join("\n"));What it prints
Output
Answer using only these passages. Cite each claim with its number.[1] On April 27, CATL and HyperStrong signed a strategic cooperation agreement on sodium-ion batteries for energy storage in Ningde, Fujian. [when: April 27 -> Apr 27, 2026 (year inferred)][1] The two parties announced a three-year partnership covering 60GWh of sodium-ion battery supply, marking a significant milestone for the industrialization of sodium-ion batteries technology. [who: The two parties -> CATL and HyperStrong][1] As CATL's first strategic partner for sodium-ion energy storage, HyperStrong will work closely with CATL in areas including technology R&D, product applications, and project deployment.[1] It also represents the largest sodium-ion battery supply agreement in the world to date, ushering in a new phase of large-scale expansion for the global sodium-ion battery industry.[1] The 60GWh sodium-ion battery cooperation marks a major milestone for both parties.[2] HyperStrong and CATL Sign 60 GWh Sodium-Ion Battery Agreement to Advance Energy Storage[2] April 27, Beijing - Beijing HyperStrong Technology Co., Ltd. ("HyperStrong") and Contemporary Amperex Technology Co., Limited ("CATL") signed a strategic cooperation agreement on sodium-ion batteries for energy storage, establishing a three-year partnership totaling 60 GWh, marking a pivotal milestone toward the large-scale deployment of sodium-ion batteries in the energy storage industry. [when: April 27, -> Apr 27, 2026 (year inferred)][2] This agreement represents the world's largest sodium-ion battery cooperation announced to date.Question: What did CATL and HyperStrong agree, and when?[1] CATL and HyperStrong Sign the World's Largest Sodium-Ion Energy ... https://www.catl.com/en/news/6812.html[2] HyperStrong and CATL Sign 60 GWh Sodium-Ion Battery Agreement to ... https://www.hyperstrong.com/en/news/company-news/95How it works
enrich: 2reads the top two results and returns their passages.- Results with
lineage: nullwere not read, so the script leaves them out of the prompt. - Each passage is sent as
enriched_text, so the model knows whoThe two partiesare and which yearApril 27was.