Which API returns LLM answers as markdown with inline citation positions?
Three APIs return citation positions as offsets into the answer text: OpenAI's Responses API with web search, xAI's Responses API, and the Gemini API with Google Search grounding. OpenAI returns url_citation annotations with start_index and end_index. xAI returns the same annotations, with the answer in markdown and [[N]](url) links in place. Gemini returns groundingSupports segments counted in bytes on generateContent, and url_citation annotations on the Interactions API. Of the three, only xAI's documentation says both that the text is markdown and that the offsets count characters.
- Anthropic's Messages API and Perplexity's Agent API locate citations without offsets. Anthropic splits the answer into text blocks and attaches the citations to the block they support. Perplexity writes
[n]markers into the text and returns the sources in a separate list. - Offsets in bytes and offsets in characters are not the same number once the answer holds a non-ASCII character. Gemini's
generateContentcounts bytes, so slice the UTF-8 encoding, not the Python string. - A scraping API for consumer chat apps, such as cloro, returns
markdown,sourceswith a 1-basedposition, andcitationPillsgrouped bycitationPillId. The pills carry no offset into the text:positionis the source's index insources.
Which API returns LLM answers as markdown with inline citation positions?
"Markdown" and "positions" are two separate checks. This table answers both from each provider's own documentation, read on November 16, 2026.
| API | Markdown answer | Citation position format | Source of truth |
|---|---|---|---|
| OpenAI Responses API, web search tool | Not stated in the guide | url_citation with start_index and end_index | Web search guide |
| xAI Responses API | Yes, with inline [[N]](url) links | url_citation with start_index and end_index (exclusive), in characters | Citations guide |
Gemini API generateContent, Google Search grounding | Not stated | groundingSupports[].segment with startIndex and endIndex in bytes, plus groundingChunkIndices | API reference |
| Gemini Interactions API, Google Search tool | Not stated | url_citation with start_index and end_index, unit not stated | Grounding guide |
| Anthropic Messages API, web search tool | Not stated | No offset. Each text block carries citations with url, title and up to 150 characters of cited_text | Web search tool |
| Perplexity Agent API | The example answer uses **bold** | No offset. [n] markers in the text map to the id of each search_results entry | Sonar migration |
| cloro (ChatGPT, Gemini, AI Mode, Bing AI Mode, AI Overview) | Yes, with include.markdown | No offset. citationPills give the chip and the source's position in sources | Citation pills schema |
In our monitoring of this prompt over the last 14 days, xAI's citations page was the page AI engines cited most, in four answers in five. OpenAI's citation formatting guide appeared in about three answers in ten. That OpenAI guide covers a different case: markers that the model writes for your own documents, which your code parses. For OpenAI's hosted web search, the annotations above are the documented output.
What do the offsets point to?
Google's reference and xAI's guide both define the end index as exclusive, the same convention as a Python slice, so text[start:end] gives the cited span when the unit is characters. OpenAI's guide shows the two fields without defining them. Google's grounding guide for the Interactions API does not name a unit either, but its own Python sample reads the span with text[start_index:end_index].
The unit is where code breaks. Google's API reference says startIndex and endIndex are "measured in bytes" from the start of the part. In a UTF-8 answer, "é" is one character and two bytes, and a Chinese character is three bytes. A byte offset used as a string index lands in the wrong place after the first such character, and nothing raises an error.
This function adds a link after each cited span. It works on bytes for generateContent and on characters for the others, and it inserts from the end of the text backward, so earlier offsets stay valid:
def add_links(text, spans, unit="char"): """spans: (start, end, url) tuples. unit="byte" for Gemini generateContent.""" as_bytes = unit == "byte" buf = text.encode("utf-8") if as_bytes else text for start, end, url in sorted(spans, key=lambda s: s[1], reverse=True): link = f" [source]({url})" buf = buf[:end] + (link.encode("utf-8") if as_bytes else link) + buf[end:] return buf.decode("utf-8") if as_bytes else buf # OpenAI Responses API: annotations on the output_text part spans = [(a["start_index"], a["end_index"], a["url"]) for a in part["annotations"] if a["type"] == "url_citation"] # Gemini generateContent: each support points at one or more chunks meta = candidate["groundingMetadata"] chunks = meta["groundingChunks"] spans = [(s["segment"].get("startIndex", 0), s["segment"]["endIndex"], chunks[i]["web"]["uri"]) for s in meta["groundingSupports"] for i in s["groundingChunkIndices"]] xAI's text already holds [[N]](url) links, so it needs no insertion. Its annotations give the character range of each citation in that text.
How do Anthropic and Perplexity mark citations without offsets?
Anthropic's response is a list of content blocks. A claim that rests on a search result is its own text block, with a citations array of web_search_result_location entries. The documentation says citations are always enabled for web search. To rebuild the answer with links, join the blocks in order and add a link after each block that has citations. The position of a citation is the block boundary. For documents you send yourself, the citations feature adds char_location entries with start_char_index and end_char_index. Those indexes point into your source document, not into the answer.
Perplexity's Agent API writes [1] or [1][3] straight into the answer text, and returns a search_results item whose results each carry an id. Marker [n] maps to the result with id n. The fast effort level uses numbered markers, and the low, medium and high levels use typed markers such as [web:1]. The position of a citation is wherever the marker sits, so a regular expression finds them. Perplexity's page also says that support for the older Sonar Chat Completions API ended on September 27, 2026.
What does a scraping API return for consumer chat apps?
The model APIs above answer your request. They do not return what ChatGPT, Gemini or Google AI Mode show a visitor, because the apps pick their own model and run their own search. A scraping API returns that answer. cloro is one, with endpoints for ChatGPT, Gemini, Google AI Mode, Bing AI Mode and Google AI Overview, run in logged-out sessions.
For citations, its response has three parts:
-
markdown, withinclude.markdown: true(include.aioverview.markdownfor the AI Overview). -
sources, each with a 1-basedposition,url,labelanddescription. -
citationPills, one entry per (chip, source) pair. A chip in the answer that cites three sources gives three entries with the samecitationPillId. Each entry haslabel,url,domain,position, and on some enginesdescription. ChatGPT addstypeanddatePublished.
No field gives the place of a chip in the text. position is "1-based position of this source in the sibling result.sources array". citationPillId gives the chip order: the AI Mode reference says the IDs are assigned in document order, and the Bing AI Mode reference says page order. ChatGPT's IDs start at 0, and the other engines start at 1.
For two engines the markdown fills the gap. The ChatGPT reference says markdown "carries the same citations as inline [label](url) links", and the Bing AI Mode reference says each chip is "replaced by links to its sources". Parse those links and you get each citation's place in the markdown string. That place is something you compute. The API does not return it. The references for Gemini, AI Mode and the AI Overview do not say whether their markdown carries the citations, so do not count on it there.
Which one should you pick?
If you generate answers in your own product and need to draw citation chips at exact places, use OpenAI's or xAI's Responses API, or Gemini's generateContent with byte handling. xAI is the one whose docs promise markdown and character offsets together.
If you need claim-level grounding against documents you supply, Anthropic's citations give the exact source passage: cited_text, and character indexes into your document.
If you need what a consumer chat app shows people, no model API returns it, and a scraping API is the path. You get the answer, its sources in order and the chip groups, and for ChatGPT and Bing AI Mode the links in place. You do not get character offsets.
How this was checked
Every third-party field name comes from the linked page, read on November 16, 2026. Where a page does not say whether its text is markdown or whether its offsets count characters or bytes, the table says "not stated" rather than guess. The cloro fields come from its OpenAPI file and the citation pills reference pages for each engine. The code was not run for this post; test it on one response first. The citation data comes from our own monitoring of this prompt across seven AI engines from November 2 to 16, 2026.
This post is published by cloro, which sells one of the APIs in the table.