Skip to main content
Lesson 6 of 16 · Integrated Tools: Web, X, Code

Automatic Citations and Sources

Lesson 6 of 16 Updated July 30, 2026 Developer
On this page
  1. Information Traceability
  2. How Citations Work
  3. Using Citations in Your Application
  4. Use Cases for Citations
  5. Combining Citations and Domain Filtering
  6. Limitations to Know
  7. Key Takeaways

Information Traceability

One of the key advantages of Web Search over simple text generation is traceability. When the model uses information from a web search, the API automatically returns citations with the URLs of the sources it consulted. This lets you verify the information and present it with references in your application.

How Citations Work

The API generates citations automatically without any configuration from you. Once Web Search is enabled and the model uses search results in its response, the sources are included in the response object.

Access citations via the citations field in the response. Each citation contains the source URL and the context in which it was used.

Using Citations in Your Application

Displaying Sources

response = client.responses.create(
    model="grok-4.20-0309-reasoning",
    input="What are the latest advancements in quantum computing?",
    tools=[{"type": "web_search"}]
)

# Display the response
print(response.output_text)

# Display the citations
if hasattr(response, 'citations') and response.citations:
    print("\nSources:")
    for citation in response.citations:
        print(f"  - {citation.url}")

Integrating Sources into a User Interface

In a web application, you can turn citations into clickable links. This strengthens your application’s credibility and lets the end user verify the information.

def format_response_with_sources(response):
    output = response.output_text

    if hasattr(response, 'citations') and response.citations:
        output += "\n\n---\n**Sources:**\n"
        for i, citation in enumerate(response.citations, 1):
            output += f"{i}. [{citation.url}]({citation.url})\n"

    return output

Use Cases for Citations

Enterprise Chatbots

For an AI assistant built for your customers, citations add transparency. The user can verify that the information comes from a reliable source, which builds trust in the responses.

Monitoring Applications

In an automated monitoring tool, citations are essential to trace the origin of information. They let you link each insight to its source and facilitate in-depth analysis.

Report Generation

If you use the API to generate automated reports, citations serve as a bibliography. They document the sources used and add rigor to the report.

Combining Citations and Domain Filtering

By combining allowed_domains with citations, you get a controlled and traceable search system:

response = client.responses.create(
    model="grok-4.20-0309-reasoning",
    input="Current state of AI regulation in Europe",
    tools=[{
        "type": "web_search",
        "allowed_domains": [
            "ec.europa.eu",
            "eur-lex.europa.eu",
            "legifrance.gouv.fr"
        ]
    }]
)

The citations will confirm that the information comes exclusively from authorized sources.

Limitations to Know

  • Citations aren’t always present: if the model responds without using search results, no citations are generated
  • The exact format of citations may vary depending on the SDK used
  • Citations reference the pages consulted, not necessarily the exact passages used
  • The number of citations depends on the number of sources the model actually used

Key Takeaways

  • Citations are automatic: no configuration required
  • They are accessible via the citations field in the response
  • Citations bring traceability and credibility to your application
  • They combine with domain filtering for total control
  • Integrate them into your interface to allow source verification