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_idstrbodyrequired

Returns: Chat

show properties (7)hide properties (7)
idstringrequired
created_atstringrequired
code_idstringrequired
version_idOptional[string]
titleOptional[string]
chat_typeChatTyperequired
total_messagesintegerrequired

create_for_code

POST /v1/chats

result = await client.chats.create_for_code(
    code_id=code_id,
)

Arguments:

code_idstrbodyrequired

Returns: Chat

show properties (7)hide properties (7)
idstringrequired
created_atstringrequired
code_idstringrequired
version_idOptional[string]
titleOptional[string]
chat_typeChatTyperequired
total_messagesintegerrequired

list

GET /v1/chats

Chats in the project.

result = await client.chats.list()

Arguments:

paramsChatListParams | Nonequery
default:None
pageinteger
page_sizeinteger
code_idstring
version_idstring
chat_typeChatType
order_by'created_at' | 'updated_at'
order'desc' | 'asc'
with_paginationboolquery
default:False

Return type by call:

  • with_pagination=True → PaginatedResource[Chat]
  • with_pagination=False → Pagination[Chat]
show properties (6)hide properties (6)
resultsarray of Chat
show properties (7)hide properties (7)
idstringrequired
created_atstringrequired
code_idstringrequired
version_idOptional[string]
titleOptional[string]
chat_typeChatTyperequired
total_messagesintegerrequired
pageintegerrequired
page_sizeintegerrequired
morebooleanrequired

Whether more pages follow.

total_observationsintegerrequired

Total results across all pages.

total_pagesintegerrequired

get

GET /v1/chats/{chat_id}

result = await client.chats.get(
    chat_id=chat_id,
)

Arguments:

chat_idstrpathrequired

Returns: Chat

show properties (7)hide properties (7)
idstringrequired
created_atstringrequired
code_idstringrequired
version_idOptional[string]
titleOptional[string]
chat_typeChatTyperequired
total_messagesintegerrequired

messages

GET /v1/chats/{chat_id}/messages

result = await client.chats.messages(
    chat_id=chat_id,
)

Arguments:

chat_idstrpathrequired

Returns: ResultsResponse[ChatMessage]

show properties (1)hide properties (1)
resultsarray of ChatMessage
show properties (8)hide properties (8)
idstringrequired
created_atstringrequired
chat_idstringrequired
chat_roleChatMessageRolerequired
messagestringrequired
refsarray of InlineRef
show properties (6)hide properties (6)
idstringrequired
typestringrequired
sourcestringrequired
ref_indinteger
nameOptional[string]
is_staleboolean
has_proposalboolean
proposal_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_idstrpathrequired
bodyChatCreateMessageBodybodyrequired
messagestringrequired
is_retryboolean
approval_idstring
is_approvedboolean

Returns: ChatMessage

show properties (8)hide properties (8)
idstringrequired
created_atstringrequired
chat_idstringrequired
chat_roleChatMessageRolerequired
messagestringrequired
refsarray of InlineRef
show properties (6)hide properties (6)
idstringrequired
typestringrequired
sourcestringrequired
ref_indinteger
nameOptional[string]
is_staleboolean
has_proposalboolean
proposal_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_idstrpathrequired

Returns: 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_idstrpathrequired
session_tokenstrbodyrequired
bodyChatCreateMessageBodybodyrequired
messagestringrequired
is_retryboolean
approval_idstring
is_approvedboolean

Returns: AsyncGenerator[ChatMessageStream]

On this page