Chats
Python SDK reference for the chats resource
Warning
The SDKs are in research preview. Their interfaces may change between minor versions until 1.0.
Access this resource from client.chats. Both async and sync clients expose the same methods.
create_for_analysis
POST /v1/chats
result = await client.chats.create_for_analysis(
version_id=version_id,
)Arguments:
version_idstrbodyrequiredReturns: Chat
show properties (7)hide properties (7)
idstringrequiredcreated_atstringrequiredcode_idstringrequiredversion_idOptional[string]titleOptional[string]chat_typeChatTyperequiredtotal_messagesintegerrequiredcreate_for_code
POST /v1/chats
result = await client.chats.create_for_code(
code_id=code_id,
)Arguments:
code_idstrbodyrequiredReturns: Chat
show properties (7)hide properties (7)
idstringrequiredcreated_atstringrequiredcode_idstringrequiredversion_idOptional[string]titleOptional[string]chat_typeChatTyperequiredtotal_messagesintegerrequiredlist
GET /v1/chats
Chats in the project.
result = await client.chats.list()Arguments:
paramsChatListParams | NonequeryNonepageintegerpage_sizeintegercode_idstringversion_idstringchat_typeChatTypeorder_by'created_at' | 'updated_at'order'desc' | 'asc'with_paginationboolqueryFalseReturn type by call:
with_pagination=True→PaginatedResource[Chat]with_pagination=False→Pagination[Chat]
show properties (6)hide properties (6)
resultsarray of Chatshow properties (7)hide properties (7)
idstringrequiredcreated_atstringrequiredcode_idstringrequiredversion_idOptional[string]titleOptional[string]chat_typeChatTyperequiredtotal_messagesintegerrequiredpageintegerrequiredpage_sizeintegerrequiredmorebooleanrequiredWhether more pages follow.
total_observationsintegerrequiredTotal results across all pages.
total_pagesintegerrequiredget
GET /v1/chats/{chat_id}
result = await client.chats.get(
chat_id=chat_id,
)Arguments:
chat_idstrpathrequiredReturns: Chat
show properties (7)hide properties (7)
idstringrequiredcreated_atstringrequiredcode_idstringrequiredversion_idOptional[string]titleOptional[string]chat_typeChatTyperequiredtotal_messagesintegerrequiredmessages
GET /v1/chats/{chat_id}/messages
result = await client.chats.messages(
chat_id=chat_id,
)Arguments:
chat_idstrpathrequiredReturns: ResultsResponse[ChatMessage]
show properties (1)hide properties (1)
resultsarray of ChatMessageshow properties (8)hide properties (8)
idstringrequiredcreated_atstringrequiredchat_idstringrequiredchat_roleChatMessageRolerequiredmessagestringrequiredrefsarray of InlineRefshow properties (6)hide properties (6)
idstringrequiredtypestringrequiredsourcestringrequiredref_indintegernameOptional[string]is_stalebooleanhas_proposalbooleanproposal_statusOptional['pending' | 'approved' | 'rejected']sync
POST /v1/chats/{chat_id}/sync
Send a message and wait for the full reply.
result = await client.chats.sync(
chat_id=chat_id,
body=body,
)Arguments:
chat_idstrpathrequiredbodyChatCreateMessageBodybodyrequiredmessagestringrequiredis_retrybooleanapproval_idstringis_approvedbooleanReturns: ChatMessage
show properties (8)hide properties (8)
idstringrequiredcreated_atstringrequiredchat_idstringrequiredchat_roleChatMessageRolerequiredmessagestringrequiredrefsarray of InlineRefshow properties (6)hide properties (6)
idstringrequiredtypestringrequiredsourcestringrequiredref_indintegernameOptional[string]is_stalebooleanhas_proposalbooleanproposal_statusOptional['pending' | 'approved' | 'rejected']session_token
POST /v1/chats/{chat_id}/session-token
A single-use token for one chat stream. Generate it server-side.
result = await client.chats.session_token(
chat_id=chat_id,
)Arguments:
chat_idstrpathrequiredReturns: str
stream
POST /v1/chats/{chat_id}/stream
Use session_token() for initial request
Send a message and stream the reply.
result = await client.chats.stream(
chat_id=chat_id,
session_token=session_token,
body=body,
)Arguments:
chat_idstrpathrequiredsession_tokenstrbodyrequiredbodyChatCreateMessageBodybodyrequiredmessagestringrequiredis_retrybooleanapproval_idstringis_approvedbooleanReturns: AsyncGenerator[ChatMessageStream]

