← Glean-ia-acs Β· Day 46 of 56
Level 400 β€” Builder Β· APIs30 minNIST MEASURE

The Chat API

Grounded answers with citations and tool use

You'll be able to

Read first

Day 4 Lab

  1. Send a question to the Chat API as a single user message.
  2. Read the answer text from the response fragments.
  3. Pull the citations and list the documents the answer rests on.
  4. 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

Pick an answer β€” you'll see if it's right and why.

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?

Pass threshold 80% Β· week 7 quiz

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.”

Next Β· Week 7 Day 5
Client API vs. Indexing API