API / cite-tool-sources-in-api-responses

API

Cite tool sources in API responses

Cite tool sources in API responses

When Grok uses tools such as web search, citations arrive in two forms: All Citations (response.citations — every URL the model encountered, returned by default) and Inline Citations (markdown [[N]](url) in the answer text plus structured metadata). Not every URL in All Citations appears in the final answer. Enabling inline citations does not force a citation on every reply — the model decides. Wire search first: Add web search to an API request.

All Citations (default)

After a tool-using call, read response.citations for the full URL list. You do not need an extra flag for this list.

Inline citations

On the Responses API, inline citations are on by default. Disable them with include=["no_inline_citations"].

In the xAI Python SDK, inline citations are off by default. Enable them with include=["inline_citations"] on chat.create().

import os
from xai_sdk import Client
from xai_sdk.chat import user
from xai_sdk.tools import web_search

client = Client(api_key=os.getenv("XAI_API_KEY"))

chat = client.chat.create(
    model="grok-4.6",
    tools=[web_search()],
    include=["inline_citations"],
)
chat.append(user("What were the top headlines about renewable energy this week? Cite sources."))
response = chat.sample()
print(response.content)
print("All citations:", response.citations)

curl (Responses API + web_search)

curl https://api.x.ai/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{
  "model": "grok-4.6",
  "input": [
    {
      "role": "user",
      "content": "What were the top headlines about renewable energy this week? Cite sources."
    }
  ],
  "tools": [
    {"type": "web_search"}
  ]
}'

Inline markers appear in the text as [[N]](url) when the model cites mid-answer. To turn inline off on Responses API, add "include": ["no_inline_citations"] to the body.

Pitfalls

  • Expecting every All Citations URL to show up in the prose — the list is the full encounter set; the answer may use a subset.
  • Leaving SDK inline off and wondering why markdown [[N]] never appears — pass include=["inline_citations"] on chat.create().
  • Assuming include=["inline_citations"] guarantees a citation every time — the model still chooses when to cite.