API: Ana Endpoints
How to programmatically interact with Ana
API Docs
For a better understanding of fundamental concepts, we recommend reading the “About TextQL” section as well.
All endpoints required Basic
HTTP authentication. Refer to the environment variables for values:
GET /api/ana
The Ana API allows you to send queries to Ana, your team’s personal data scientist. Ana uses various tools to fetch data from connected sources and provide data-driven insights.
Request parameters
Parameter | Type | Required | Description |
---|---|---|---|
dataset | string | Optional | The dataset to use for the query. If not provided, Ana will try to infer the appropriate dataset based on the query. |
useOntology | boolean | Optional | Whether to use the Ontology tool to query the data warehouse. Defaults to false . |
ontologyConnectorId | integer | Required if useOntology is true | The ID of the data warehouse connector to use for the Ontology query. You can create a connector using the Ontology Connector API. |
clifford | boolean | Optional | Whether to use the Clifford system for fetching datasets. Defaults to false . |
query | string | Required | The query to send to Ana. This should be URI-encoded. |
Response
The response is a text/event-stream
of JSON-encoded objects representing the steps Ana takes to answer the query.
On the front-end, we recommend using EventSource’s named events for event handing.
Each object in the stream represents a “block” - a unit of work or output from Ana. Blocks are streamed in order, and have a unique id
field.
As Ana works on a block, it may stream updated versions of the same block id
with more content. Once Ana moves on to a new block id
, you can consider the previous block complete.
Example response:
Block types
TextBlock
Represents a piece of text output, such as an intermediate step in reasoning or a final answer.
Field | Type | Description |
---|---|---|
tag | string | Always "TextBlock" . |
contents | string | The text content of the block. |
id | string | A unique identifier for this block. |
Sure, let’s break out the result
object into its own table. Here’s the updated documentation:
OntologyBlock
Represents Ana using the Ontology tool to query a connected data warehouse.
Field | Type | Description |
---|---|---|
tag | string | Always "OntologyBlock" . |
id | string | A unique identifier for this block. |
contents | object | Details about the Ontology query. Contains fields: - query : The natural language query.- result : Object with details of query execution (see Result table below). |
tool_call_id | string | Unique identifier for this ontology query. |
Result
Details about the execution of an Ontology query.
Field | Type | Description |
---|---|---|
complete | boolean | Indicates if the query execution is finished. |
connectorId | integer | ID of the data warehouse connector used. |
queryClassification | object | Whether the query was classified as an object or metric. |
userPrompt | string | The original user query. |
segmentation | object | Information about the segmentation of the query. |
object | object | Represents the main object of the query. |
groupingsStarted | array | List of initial grouping details. |
groupingsFound | array | List of final grouping details. |
metricsQuery | object | Represents metrics identified in the query. |
selectedAttributes | array | List of attributes used in the query. |
ordersStarted | array | List of initial ordering details. |
ordersFound | array | List of final ordering details. |
directionFound | string | Sorting direction, either “asc” or “desc”. |
sqlQuery | string | The generated SQL query. |
sqlResult | object | The results of the SQL query execution. |
preview | object | Preview of the loaded data. |
oai_output | string | Message for the user about the data loaded. |
Example:
PythonBlock
Python code execution for data analysis.
Field | Type | Description |
---|---|---|
tag | string | Always "PythonBlock" . |
contents | string | The Python code being executed. |
results | array | The results of executing the Python code. Each result is an object with a tag field indicating its type ("TextResult" for plain text output, or "ImageUrlResult" for a generated image). Only present when code execution is complete. |
id | string | A unique identifier for this block. |
Handling block updates
As Ana works on answering a query, it will stream updated blocks with the same id
as it makes progress. Your application is responsible for replacing any prior blocks with the same id
with the latest streamed version of that block.
For example, you may receive a TextBlock
that represents Ana’s current draft of the answer. As Ana continues working, you will receive TextBlock
s with the same id
but expanded contents
as Ana builds out the answer. You should replace the prior block contents with the new expanded version.
Error handling
If an error occurs, an ErrorBlock
will be streamed with details about the error. Your application should handle this gracefully and display an appropriate message to the user.
GET /api/ana/chat/summary
Here’s the documentation for the /api/ana/chat/summary
endpoint, written in the style of Stripe API docs:
Chat Summary
Retrieve a summary of all chats, including titles and timestamps of the last user message in each chat.
Response
Returns an array of chat summary objects.
Chat Summary Object
Field | Type | Description |
---|---|---|
innerId | string | Unique identifier for the chat. |
innerVal | object | Contains the chat summary details. |
innerVal.id | string | Unique identifier for the chat (same as innerId ). |
innerVal.orgId | string | ID of the organization the chat belongs to. |
innerVal.engine | string | JSON string representing the chat engine configuration. |
innerVal.summary | string | A brief summary or title of the chat. |
innerVal.lastUserMessage | object | Details about the last user message in the chat. |
innerVal.lastUserMessage.timestamp | string | ISO 8601 timestamp of when the last user message was sent. |
Example Request
Example Response
This endpoint returns an array of chat summary objects. Each object contains an innerId
field, which is a unique identifier for the chat, and an innerVal
field, which contains the details of the chat summary.
GET /api/ana/:chat_id
Retrieve the messages of a specific chat, given its unique identifier.
Path Parameters
Parameter | Type | Description |
---|---|---|
chatId | string | The unique identifier of the chat to retrieve messages from. |
Response
Returns an array of arrays, where each inner array represents a message in the chat, consisting of blocks. Each block is an object with an innerId
and innerVal
field – the format matches GET /api/ana
.
Message Object
Field | Type | Description |
---|---|---|
innerId | integer | Unique identifier for the message within the chat. |
innerVal | object | Contains the message details. |
Message Details Object
Field | Type | Description |
---|---|---|
author | object | Details about the author of the message. |
chatId | string | The unique identifier of the chat the message belongs to. |
timestamp | string | ISO 8601 timestamp of when the message was sent. |
body | array | An array of message blocks (see below). |
messageIdx | integer | The index of the message within the chat. |
Author Object
Field | Type | Description |
---|---|---|
tag | string | The type of the author, either “User” or “Assistant”. |
name | string | (Optional) The name of the user, if the author is a user. |
contents | string | (Optional) The unique identifier of the user, if the author is a user. |
Message Block Object
Field | Type | Description |
---|---|---|
id | string | Unique identifier for the message block. |
tag | string | The type of the message block (e.g., “TextBlock”). |
contents | string | The contents of the message block. |