Chat API: Talk to DataHub Agents
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:
| API | URL |
|---|---|
| GraphQL | https://<tenant>.acryl.io/api/graphql |
| Streaming | https://<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:
| Field | Description |
|---|---|
title | Generated from the first message if not set. |
originType | Where 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. |
agentUrn | The 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:
| Field | Required | Description |
|---|---|---|
conversationUrn | Yes | The URN from step 1. |
text | Yes | The user's message. |
agentName | No | The URN of the agent to answer. Leave it out to keep the conversation's current agent. See below. |
viewUrn | No | A DataHub View URN that limits which assets the agent searches. |
context | No | Same 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: {...}
| Event | What to do with it |
|---|---|
message | A 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_delta | Optional. 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_suggestions | Suggested next questions, in metadata.followUpSuggestions. |
title_update | A generated title for the conversation, in message.content.text. |
agent_handoff | Ask DataHub passed the conversation to a custom agent (to_agent_urn, to_agent_name). Later messages go to that agent. |
agent_ejected | The custom agent passed the conversation back to Ask DataHub. |
error | The turn failed. Stop reading. |
complete | The 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
| Status | Meaning |
|---|---|
| 400 | conversationUrn or text is missing, or the URN is invalid. |
| 401 | The token is missing or invalid. |
| 403 | The token's user did not create this conversation. |
| 429 | Your 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 withoutagentNamego 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:
- The agent that wrote the conversation's latest reply. This includes an agent that Ask DataHub handed the conversation to.
- The agent the conversation was created for (
agentUrn). - Ask DataHub.
Manage conversations
| Operation | Purpose |
|---|---|
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
}
}
}
}
Related
- Connect your agent to a DataHub agent: use a DataHub agent from Claude, ChatGPT or another MCP client without writing code against this API.
- Use Ask DataHub directly: set up plugins and create custom agents.