How are Grok's inline citations located in response text?

The Citead team, updated

In short. Grok's annotations use start_index and end_index to locate a complete inline citation link in response text.

Definition: Grok's inline citation offsets are start_index and end_index values in each url_citation annotation on an output_text content block. They locate the citation's Markdown link in the returned response text, with the end position excluded.

Key facts

  • xAI separates a complete response.citations list from inline Markdown links embedded in the response text in its citation documentation.
  • The same documentation places structured citation metadata in an annotations array on each output_text content block, with a URL, character offsets and label.
  • Each annotation has the type url_citation, a source URL, start_index, end_index and title fields.
  • xAI defines the start as the position of the first [ and the end as the position immediately after the closing ), so the end is exclusive.
  • A Python slice using those two values extracts the exact citation Markdown from the response text.

What do the offsets point to?

The offset range covers the visible citation link, including its Markdown syntax. The documented text form is [[N]](url): N is the sequential display number and url is the source URL. If the same source appears again later, xAI's documentation says the original citation number is reused.

The annotation object supplies the data needed to connect the range to a source:

{
  "type": "url_citation",
  "url": "https://x.ai/company",
  "start_index": 208,
  "end_index": 235,
  "title": "1"
}

The example values above follow the shape shown in xAI's response example. To inspect the link itself, apply the range to the same text returned in the output_text.text field:

citation_text = content[citation.start_index:citation.end_index]

The result includes the opening [ and the closing ) because both boundary positions belong to the documented Markdown link range.

When are annotations present?

xAI documents different defaults for the Responses API and its Python SDK. For the Responses API, inline citations are enabled by default. The Python SDK requires include=["inline_citations"] to enable them, while include=["no_inline_citations"] disables them for the Responses API.

When inline citations are disabled, the response text contains no [[N]](url) Markdown links. The annotations field may still list sources encountered during search, but those annotations have no positional references into the response text. This is why a source URL in response.citations or an annotation without usable positions cannot by itself identify a visible link location.

How do search results become source URLs?

xAI's Web Search documentation describes Web Search as a tool that searches the web, browses pages and extracts information for an answer. Its API example returns the response after the tool runs, and xAI's Tools overview states that the API automatically returns source URLs for information gathered through tools.

The citation page distinguishes this source inventory from inline references. response.citations is a comprehensive list of URLs encountered during the search process, and xAI says that a URL can remain in this list even when the model does not reference it in the final answer. Positional annotations therefore answer a narrower question: which part of the returned text contains a particular inline citation link?

During streaming, xAI documents that citation links appear in chunk.content as text is generated and that accumulated inline citations are available on the final response. A parser that needs stable final offsets should read the completed response text together with its completed annotations.

FAQ

Yes. Use the two values as a Python-style half-open slice on the exact output_text.text string returned with the annotation.

Does every URL in response.citations have an inline position?

No. xAI describes response.citations as a list of all sources encountered during search. A source can appear there without being directly referenced in the final answer.

What should I inspect in a streamed response?

The final response and its accumulated annotations. xAI documents per-chunk access during streaming and a completed collection after streaming finishes.

Sources

  1. xAI, "Citations", undated
  2. xAI, "Web Search", undated
  3. xAI, "Overview", undated

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark