🚀 Simplify your work by integrating Haufe CoPilot Connect via API or MCP
Skip to Content
Guides

[Preview] Citations

Show which Haufe document grounds each part of the answer.

warning

This feature is in preview. The endpoint and the response format can change.

An answer often contains statements that your users want to verify. A citation links a part of the answer to the Haufe documents that support it. With citations, you can show next to each statement the documents it comes from.

You get the citations in two steps:

  1. Generate the answer as usual.
  2. After the answer is complete, request its citations with a separate call.

The answer does not wait for the citations, so the citations add no delay to the answer.

The same endpoint works for answers from a thread run and from a chat completion:

GET https://api.haufe.ai/agents/v1/threads/{thread_id}/messages/{message_id}/citations

info

Citations currently use only Haufe documents. Documents that users upload get no citations.

See the API reference for the full schema.

Generate an answer

Generate the answer as usual, with a chat completion or a thread run. Keep the id of the created thread (thread_id) and the id of the assistant message from the response. A chat completion also creates a thread, so its response contains a thread_id too.

warning

Request the citations only after the answer is complete. For a streamed answer, wait until the stream ends. The API stores the message at the end of the stream. A request before that gets 404 message_not_found.

Request the citations

curl --request GET \
  --url https://api.haufe.ai/agents/v1/threads/<THREAD_ID>/messages/<MESSAGE_ID>/citations \
  --header 'api-key: <API_KEY>'

The API computes the citations on each request. A request takes a few seconds.

Each citation marks a part of the answer with start and end. To show markers, insert them at end, from the last citation to the first, so the offsets of the other citations stay valid.

Response

{
  "citations": [
    {
      "start": 0,
      "end": 85,
      "text": "Während der Probezeit beträgt die Kündigungsfrist gemäß § 622 Abs. 3 BGB zwei Wochen.",
      "statements": [
        {
          "type": "source",
          "id": "HI1234567",
          "text": "Eine Probezeit kann für maximal 6 Monate vereinbart werden. Die Kündigungsfrist beträgt dann 2 Wochen."
        }
      ]
    }
  ]
}
FieldDescription
start, endPosition of the cited part in the content of the message, in UTF-16 code units.
textThe cited part of the answer.
statementsThe Haufe documents that support the cited part, the strongest first. Each document appears at most once per citation.
statements[].typeThe type of the statement. Currently always source.
statements[].idThe HI number of the document. It is equal to meta_data.hi of a source in the sources of the message.
statements[].textA passage of the document.

The citations list can be empty. This happens when the answer has no sources, or when no source supports a part of the answer.

On this page