Skip to main content

Chat API: Talk to DataHub Agents

Feature Availability
DataHub Core (OSS)
DataHub Cloud
PUBLIC BETA

Programmatic access to Ask DataHub and DataHub agents from outside DataHub is in Public Beta. Requests are subject to capacity- and quota-based rate limits.

The DataHub UI talks to Ask DataHub and to custom agents through two APIs. Your own application or agent can use the same ones:

  • GraphQL to create, list, read and delete conversations.
  • A streaming endpoint (POST /openapi/v1/ai-chat/message) to send a message and receive the agent's reply as Server-Sent Events (SSE).

DataHub saves every message, so you can always read the full transcript back through GraphQL.

Authentication​

Send a DataHub access token on every request:

Authorization: Bearer <token>

The agent acts as the user who owns the token. It can see only what that user can see. Only the user who created a conversation can send messages to it, so create and send with the same token.

The examples below use these base URLs:

APIURL
GraphQLhttps://<tenant>.acryl.io/api/graphql
Streaminghttps://<tenant>.acryl.io/openapi/v1/ai-chat/message

1. Create a conversation​

mutation createConversation($input: CreateDataHubAiConversationInput!) {
createDataHubAiConversation(input: $input) {
urn
}
}
{
"input": {
"originType": "DATAHUB_UI",
"agentUrn": null
}
}

Input fields, all optional:

FieldDescription
titleGenerated from the first message if not set.
originTypeWhere the chat came from. DATAHUB_UI (the default) shows it in the user's Ask DataHub chat list. Other values, such as MCP, keep it out of the list.
agentUrnThe agent this conversation is for. Leave it out for Ask DataHub. See Choose an agent.
context{ "text": "...", "entityUrns": ["urn:li:dataset:..."] }: background the agent should know, such as the assets the user is looking at.

The mutation returns the conversation URN, such as urn:li:dataHubAiConversation:3f1c.... Use it for every message in this conversation.

2. Send a message​

curl -N -X POST "https://<tenant>.acryl.io/openapi/v1/ai-chat/message" \
-H "Authorization: Bearer $DATAHUB_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"conversationUrn": "urn:li:dataHubAiConversation:3f1c...",
"text": "Which tables hold daily revenue, and who owns them?"
}'

Request fields:

FieldRequiredDescription
conversationUrnYesThe URN from step 1.
textYesThe user's message.
agentNameNoThe URN of the agent to answer. Leave it out to keep the conversation's current agent. See below.
viewUrnNoA DataHub View URN that limits which assets the agent searches.
contextNoSame shape as context on create: extra background for this message only.

To continue the conversation, send the next message with the same conversationUrn. The agent has the earlier messages. Send one message at a time and wait for complete before sending the next.

3. Read the response stream​

The response is text/event-stream. Each event has a name and a JSON data line:

event: message
data: {"conversation_urn": "...", "message": {"type": "THINKING", "time": 1764590000000, "actor": {"type": "AGENT"}, "content": {"text": "Searching for revenue tables..."}}}

event: message
data: {"conversation_urn": "...", "message": {"type": "TOOL_CALL", ...}}

event: message
data: {"conversation_urn": "...", "message": {"type": "TEXT", "actor": {"type": "AGENT"}, "content": {"text": "The `finance.daily_revenue` table..."}}}

event: complete
data: {...}
EventWhat to do with it
messageA step in the agent's turn. message.type is THINKING (progress), TOOL_CALL / TOOL_RESULT (the agent's searches and queries) or TEXT. The agent's TEXT message is the answer, in Markdown.
text_deltaOptional. Pieces of the answer as the model writes it ({"segment_id": "...", "text": "..."}), for showing text live. The TEXT message that follows holds the whole answer and replaces them.
follow_up_suggestionsSuggested next questions, in metadata.followUpSuggestions.
title_updateA generated title for the conversation, in message.content.text.
agent_handoffAsk DataHub passed the conversation to a custom agent (to_agent_urn, to_agent_name). Later messages go to that agent.
agent_ejectedThe custom agent passed the conversation back to Ask DataHub.
errorThe turn failed. Stop reading.
completeThe turn is finished. Stop reading.

Ignore event names you don't recognize; new ones may be added. Lines starting with : are keepalives. A turn can take several minutes when the agent runs many queries, so set a generous read timeout (the server allows up to 30 minutes).

The simplest client waits for complete and keeps the last message event whose message.type is TEXT and message.actor.type is AGENT. That is the answer.

Errors​

StatusMeaning
400conversationUrn or text is missing, or the URN is invalid.
401The token is missing or invalid.
403The token's user did not create this conversation.
429Your organization has used its Ask DataHub credits for the month.

Choose an agent​

Every conversation runs as one agent at a time.

Ask DataHub (the default). Leave agentUrn out when you create the conversation, and leave agentName out when you send. You don't need an agent URN.

A custom agent. Pass the agent's URN, such as urn:li:aiAgent:finance-analyst. Find it on the agent's page under Settings > AI > Agents, or list agents with GraphQL:

query {
listAgents(input: { start: 0, count: 50 }) {
agents {
urn
name
description
}
}
}

Set it in either place:

  • On create, as agentUrn (recommended). The conversation belongs to that agent. Messages without agentName go to it, and the chat appears on the agent's chat tab in DataHub.
  • On each message, as agentName. Use this to switch agents within a conversation. To switch back to Ask DataHub, send "agentName": "urn:li:aiAgent:ask-datahub".

When a message has no agentName, DataHub picks the agent in this order:

  1. The agent that wrote the conversation's latest reply. This includes an agent that Ask DataHub handed the conversation to.
  2. The agent the conversation was created for (agentUrn).
  3. Ask DataHub.

Manage conversations​

OperationPurpose
getDataHubAiConversation(urn)Read a conversation and all its messages (type, time, actor, content.text, agentName).
listDataHubAiConversations(start, count, query, ...)List the user's conversations. Filter with originType, participantUrn (an agent URN) or query (title text), and sort with sortInput: { sortBy: LAST_ACTIVITY }.
updateDataHubAiConversation(input: { urn, title, context })Rename a conversation or change its context.
deleteDataHubAiConversation(urn)Delete a conversation.

For example, to read back a transcript:

query getConversation($urn: String!) {
getDataHubAiConversation(urn: $urn) {
urn
title
messages {
type
time
agentName
actor {
type
actor
}
content {
text
}
}
}
}