Conversations endpoint

The Conversations endpoint lets you create a Converse conversation. In a conversation, you can use prompts to get on-demand information from documents of nearly any type or format.

Create conversation

MethodSyntax
POSTAPI_ROOT/v2/conversations

Description

Create a new conversation by making a POST request to API_ROOT/v2/conversations. You can upload files to the conversation in the same request.

There are some limitations when uploading files to a conversation:

  • Files can be up to 50 MB or 800 pages.
  • You can upload up to 100 MB per request.
  • You can have up to 100 documents per conversation.
  • There are specific supported file types.

Request body

Parameters are required unless marked as optional.

ParameterTypeDescriptionValues
namestringName of the conversation.
descriptionstringDescription of the conversation.
fileslistA list of files to process.Local file paths.
orgstringOptional. Your organization.For organization members, your organization is <ORGANIZATION-ID>. If not defined, the organization is inferred from the IB-Context header value.
If you define an org value and include the IB-Context header, the organization values must match or the request can’t complete.
workspacestringOptional. The name of your personal workspace, where the conversation is created.For organization members, your personal workspace name is your user ID. If not defined, the workspace is inferred from the IB-Context header value.
enable_object_detectionbooleanOptional. Defines whether to enable object detection for the processed file. Object detection includes support for extracting tables and checkboxes.true, false. Default false.

Response status

StatusMeaning
201Created conversation.

Response schema

KeyTypeDescription
idstringA unique identifier for the conversation.
namestringName of the conversation.
upload_statusobjectContains a summary of the upload status for uploaded files.
upload_status/successlistLists all files successfully uploaded to the conversation.
upload_status/failurelistLists all files that failed to upload to the conversation, and the reason why.

Examples

Request (curl)

$curl "${API_ROOT}/v2/conversations" \
> -H "Authorization: Bearer ${API_TOKEN}" \
> -H "IB-Context: ${IB_CONTEXT}"\
> -F name="Sample Conversation Name" \
> -F description="Sample Conversation Description" \
> -F org="<ORGANIZATION-ID>" \ # Optional for community accounts
> -F workspace="<WORKSPACE-NAME>" \ # Optional for community accounts
> -F files="@/path/to/test.pdf" \
> -F files="@/path/to/test2.pdf"

Request (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6
7result = client.conversations.create(
8 name="Sample Conversation Name",
9 description="Sample Conversation Description",
10 org="<ORGANIZATION-ID>", # Optional for community accounts
11 workspace="<WORKSPACE-NAME>", # Optional for community accounts
12 files=['test.pdf', 'test2.pdf'])

Response

1{
2 "id": "f2ef9702-b018-4a45-9b2e-d1fb575b42ed",
3 "name": "Conversation 2023-08-23 11:40:30.669832",
4 "upload_status": {
5 "success": [
6 {
7 "name": "test.pdf"
8 },
9 {
10 "name": "test2.pdf"
11 }
12 ],
13 "failure": []
14 }
15}

List conversations

MethodSyntax
GETAPI_ROOT/v2/conversations

Description

Return a list of conversations you’ve created by sending a GET request to API_ROOT/v2/conversations.

Organization admins can access a list of all conversations in the organization, not just conversations they created.

Query parameters

Query parameterDescription
sort_keyOptional. Sort the returned conversations by when they were created (created_at) or updated (updated_at).
sort_is_ascendingOptional. Set the sort order.
search_stringOptional. Filter for conversations with the specified string.

Request body

There is no request body. Use query parameters to filter your results, if needed.

Response status

StatusMeaning
200Success.

Response schema

KeyTypeDescription
conversationslistList of conversations.
conversations/idstringThe conversation ID.
conversations/namestringThe conversation name.
conversations/descriptionstringThe conversation description.

Examples

Request (curl)

$curl "${API_ROOT}/v2/conversations" \
> -H "Authorization: Bearer ${API_TOKEN}"`
> -H "IB-Context: ${IB_CONTEXT}"

Request (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6conversations = client.conversations.list()

Response

1{
2 "conversations": [
3 {
4 "id": "66bd3eb8-36c7-4aaa-9f95-49c593add1e8",
5 "name": "Conversation 2023-08-28 12:07:23.932130",
6 "description": "Sample Conversation"
7 },
8 {
9 "id": "7196d351-0302-4d67-9ce8-b06c3bec8709",
10 "name": "Conversation 2023-08-28 12:09:50.449657",
11 "description": ""
12 }
13 ]
14}

Conversation information

MethodSyntax
GETAPI_ROOT/v2/conversations/<CONVERSATION-ID>

Description

Retrieve information about a conversation, such as its state and a list of documents in the conversation, by making a GET request to API_ROOT/v2/conversations/<CONVERSATION-ID>.

Request body

There is no request body. Use the request URL to provide the conversation ID.

Response status

StatusMeaning
200Success.

Response schema

KeyTypeDescription
idstringUnique identifier for the conversation.
namestringName of the conversation.
descriptionstringDescription of the conversation.
statestringThe state of the conversation:

- COMPLETE: Ready to start a conversation.
- FAILED: Not able process any of the uploaded files.
- RUNNING: Still processing the uploaded files.
documentslistA list of all uploaded and processed documents in the conversation.
documents/idintegerThe uploaded document’s ID. Use this value when sending conversation prompts to specify the document to query.
documents/namestringName of the document.

Examples

Request (curl)

$curl "${API_ROOT}/v2/conversations/<CONVERSATION-ID>" \
> -H "Authorization: Bearer ${API_TOKEN}"`
> -H "IB-Context: ${IB_CONTEXT}"

Request (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6result = client.conversations.status(<CONVERSATION-ID>)

Response

1{
2 "id": "<CONVERSATION-ID>",
3 "name": "Sample Conversation",
4 "description": "Sample Description",
5 "state": "COMPLETE",
6 "documents": [
7 {
8 "id": <DOCUMENT-ID>,
9 "name": "test.pdf"
10 }
11 ]
12}

Converse with a document

MethodSyntax
POSTAPI_ROOT/v2/conversations/<CONVERSATION-ID>/prompts

Description

Query a document in your conversation by making a POST request to API_ROOT/v2/conversations/<CONVERSATION-ID>/prompts.

Request body

Parameters are required unless marked as optional.

ParameterTypeDescriptionValues
questionstringAn input prompt. This can include any question or request supported by Converse, except for plot graphs.
document_idslistA document ID for the document to converse with. You can converse with one document at a time. Document IDs are single integer values that you must pass as a list.List of one valid document ID integer.
You can get a list of document IDs in your conversation with a Conversation information request.
modestringThe model to use to answer the question. Supports the standard (default) and advanced (advanced) models. If unspecified, the standard model is used. See Choosing a model for details about each model.
The multistep model is not supported for queries made by API.
default (standard model), advanced (advanced model)

Response status

StatusMeaning
200Success.

Response schema

KeyTypeDescription
prompt_idstringThe ID of the prompt.
answerstringThe answer to the question asked.

Examples

Request (curl)

$curl "${API_ROOT}/v2/conversations/<CONVERSATION-ID>/prompts" \
> -H "Authorization: Bearer ${API_TOKEN}" \
> -H "IB-Context: ${IB_CONTEXT}"
> -H "Content-Type: application/json" \
> -d '{
> "question": "What is the main topic of the document?",
> "document_ids": [<DOCUMENT-ID>],
> "mode": "default"
> }'

Request (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6answer = client.conversations.converse(conversation_id='<CONVERSATION-ID>',
7 question="What is the main topic of the document?",
8 document_ids=['<DOCUMENT-ID>'],
9 mode="default")

Response

1{
2 "prompt_id": "5b7057f8e3a04cc3a68e092bef78927e",
3 "answer": "The document is a receipt for an Uber trip on March 3, 2024."
4}

Add documents to conversation

MethodSyntax
POSTAPI_ROOT/v2/conversations/<CONVERSATION-ID>/documents

Description

Upload documents to a conversation by making a POST request to API_ROOT/v2/conversations/<CONVERSATION-ID>/documents.

There are some limitations when uploading files to a conversation:

  • Files can be up to 50 MB or 800 pages.
  • You can upload up to 100 MB per request.
  • You can have up to 100 documents per conversation.
  • There are specific supported file types

Request body

Parameters are required unless marked as optional.

KeyTypeDescriptionValues
fileslistA list of files to upload to the conversation.Local file paths.
process_filesbooleanOptional. Set whether to process the files upon upload.true, false. Default true.

Response status

StatusMeaning
201Documents uploaded and processed successfully.
400Documents failed to upload.

Response schema

KeyTypeDescription
upload_statusobjectContains a summary of upload status for uploaded files.
upload_status/successlistLists all files successfully uploaded to the conversation.
upload_status/failurelistLists all files that failed to upload to the conversation, and the reason why.

Examples

Request (curl)

$curl "${API_ROOT}/v2/conversations/<CONVERSATION-ID>/documents" \
> -H "Authorization: Bearer ${API_TOKEN}" \
> -H "IB-Context: ${IB_CONTEXT}"\
> -F files="@/path/to/test.pdf" \
> -F files="@/path/to/test2.pdf"

Request (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6status = client.conversations.add_documents('<CONVERSATION-ID>',
7 files=['test.pdf', 'test2.pdf'])

Response

1{
2 "upload_status": {
3 "success": [
4 {
5 "name": "test2.pdf"
6 }
7 ],
8 "failure": [
9 {
10 "name": "test.pdf",
11 "reason": "File already exists."
12 }
13 ]
14 }
15}

Delete documents from conversation

MethodSyntax
DELETEAPI_ROOT/v2/conversations/<CONVERSATION-ID>/documents

Description

Delete documents from a conversation by making a DELETE request to API_ROOT/v2/conversations/<CONVERSATION-ID>/documents.

You can get a list of document IDs in your conversation with a Conversation information request.

Request body

Parameters are required unless marked as optional.

KeyTypeDescriptionValues
idslistA list of document IDs for the documents to delete from the conversation.List of valid document ID integers.

Response status

StatusMeaning
204Documents successfully deleted. No content returned.

Response schema

No content is returned for successful requests.

Examples

Request (curl)

$curl -X "DELETE" "${API_ROOT}/v2/conversations/<CONVERSATION-ID>/documents" \
> -H "Authorization: Bearer ${API_TOKEN}" \
> -H "IB-Context: ${IB_CONTEXT}"\
> -H "Content-Type: application/json" \
> -d '{"ids": [<DOCUMENT-ID>]}'

Request (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6status = client.conversations.delete_documents('<CONVERSATION-ID>',
7 ids=[<DOCUMENT-ID>])

Get document metadata

MethodSyntax
GETAPI_ROOT/v2/conversations/<CONVERSATION-ID>/documents/<DOCUMENT-ID>

Description

Retrieve metadata for a document in a conversation by making a GET request to API_ROOT/v2/conversations/<CONVERSATION-ID>/documents/<DOCUMENT-ID>.

Request body

There is no request body. Use the request URL to specify the conversation and document.

Response status

StatusMeaning
200Success.

Response schema

KeyTypeDescription
idintegerThe document ID.
ibdoc_pathstringPath to the document’s internal representation.
namestringThe name of the document.
metadatalistA collection of additional, possibly dynamic, metadata properties associated with the document. The structure of this object can vary depending on the document’s content and type.

Examples

Request (curl)

$curl "${API_ROOT}/v2/conversations/<CONVERSATION-ID>/documents/<DOCUMENT-ID>" \
> -H "Authorization: Bearer ${API_TOKEN}"

Request (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6status = client.conversations.get_document_metadata('<CONVERSATION-ID>',
7 document_id=<DOCUMENT-ID>)

Response

1{
2 "id": <DOCUMENT-ID>,
3 "ibdoc_path": "username/my-repo/fs/Instabase Drive/aihub/9ff02b54-d7df-406d-a7ae-f17f9b90e6ec/documents/out/test_eJwrSS0u0StISQMADpcDKQ==.pdf.ibdoc",
4 "name": "test.pdf",
5 "metadata": [
6 {
7 "metadata_list": null,
8 "layout": {
9 "processed_image_path": "joe/my-repo/fs/Instabase Drive/aihub/9ff02b54-d7df-406d-a7ae-f17f9b90e6ec/documents/out/original/images/test_eJwrSS0u0StISQMADpcDKQ==.pdf_p0.JPEG.jpeg",
10 "thumbnail_image_path": "joe/my-repo/fs/Instabase Drive/aihub/9ff02b54-d7df-406d-a7ae-f17f9b90e6ec/documents/out/original/thumbnails/test_eJwrSS0u0StISQMADpcDKQ==.pdf_p0.JPEG.JPEG",
11 "model_training_image_path": "",
12 "page_input_path": "",
13 "width": 2550,
14 "height": 3301,
15 "corrected_rotation": 0,
16 "origin_pos": [
17 0,
18 0
19 ],
20 "is_blurry": false,
21 "blur_factor": 0,
22 "is_image_page": true,
23 "original_page_number": 0
24 },
25 "annotation_data": null,
26 "pdf_doc_metadata": null
27 }
28 ]
29}

Update conversation information

MethodSyntax
PUTAPI_ROOT/v2/conversations/<CONVERSATION-ID>

Description

Update a conversation name or description by making a PUT request to API_ROOT/v2/conversations/<CONVERSATION-ID>. The new values are passed using query parameters, such as API_ROOT/v2/conversations/<CONVERSATION-ID>?name=<CONVERSATION-NAME>&description=<CONVERSATION-DESCRIPTION>.

Query parameters

Query parameterDescription
nameThe name of the conversation.
descriptionA description of the conversation.

Response status

StatusMeaning
204Conversation details successfully updated. No content returned.
500Internal server error. Failed to update conversation details.

Response schema

No content is returned for successful requests. In case of an internal server error, an error message is provided in the response body.

Examples

Request (curl)

$curl -X "PUT" "${API_ROOT}/v2/conversations/<CONVERSATION-ID>?name=<CONVERSATION-NAME>&description=<CONVERSATION-DESCRIPTION>" \
> -H "Authorization: Bearer ${API_TOKEN}" \
> -H "IB-Context: ${IB_CONTEXT}"\
> -H "Content-Type: application/json"

Request (Python SDK)

1from aihub import AIHub
2
3client = AIHub(api_root="<API-ROOT>",
4 api_key="<API-TOKEN>",
5 ib_context="<IB-CONTEXT>")
6status = client.conversations.update('<CONVERSATION-ID>',
7 name='<CONVERSATION-NAME>',
8 description='<CONVERSATION-DESCRIPTION>')
Was this page helpful?