The Chat API
Grounded answers with citations and tool use
You'll be able to
- Call the Chat API to get a grounded, cited answer
- Read citations from the response to verify the answer's sources
Read first
Day 4 Lab
- Send a question to the Chat API as a single user message.
- Read the answer text from the response fragments.
- Pull the citations and list the documents the answer rests on.
- Treat an answer with no citations as ungrounded β verify before you act on it.
Working Example: Read the Citations
The Chat API grounds its answer in your content and returns the citations that back it. Always read those citations β they are how you measure whether the answer is trustworthy. Verified against api_clients.
import os
from glean import Glean
client = Glean(
instance=os.environ["GLEAN_INSTANCE"],
api_token=os.environ["GLEAN_API_TOKEN"],
actas_user=os.environ["END_USER_EMAIL"],
)
response = client.client.chat.create(
messages=[
{"author": "USER", "fragments": [{"text": "What is our PTO carryover policy?"}]}
],
)
answer = response.messages[-1]
print("Answer:", "".join(f.text for f in answer.fragments if f.text))
# The citations are the grounding β no citations means no trustworthy source.
for c in answer.citations or []:
doc = c.source_document
print("Cited:", doc.title, "->", doc.url)
If citations is empty, the answer is ungrounded β surface that to the user rather than presenting it as fact. Verified against api_clients.
Check for understanding
An answer has no citations. What does that tell you, and what should you do before trusting it?
Check yourself
1. Which set of languages does Glean ship typed Developer Platform clients for?
2. Why does a user-scoped token return different results for two different users running the same query?
3. In a Chat API response, what do the citations tell you?
4. You need to make 10,000 support tickets searchable in Glean. Which API do you use?
5. When pushing documents through the Indexing API, why must you include permission metadata?
In 10 seconds
βThe Chat API returns a grounded answer AND the citations behind it. Reading those citations is the measurement step β no source, no trust. The answer is only as good as what it cites.β
Client API vs. Indexing API