Chats
TypeScript 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.
createForAnalysis
POST /v1/chats
const result = await client.chats.createForAnalysis(versionId);Arguments:
versionIdstringbodyrequiredReturns: Chat
show properties (7)hide properties (7)
idstringrequiredcreated_atstringrequiredcode_idstringrequiredversion_idstring | nullrequiredtitlestring | nullrequiredchat_typeChatTyperequiredtotal_messagesnumberrequiredcreateForCode
POST /v1/chats
const result = await client.chats.createForCode(codeId);Arguments:
codeIdstringbodyrequiredReturns: Chat
show properties (7)hide properties (7)
idstringrequiredcreated_atstringrequiredcode_idstringrequiredversion_idstring | nullrequiredtitlestring | nullrequiredchat_typeChatTyperequiredtotal_messagesnumberrequiredlist
GET /v1/chats
Chats in the project.
const result = await client.chats.list();Arguments:
queryChatListParamsquerypagenumberpage_sizenumbercode_idstringversion_idstringchat_typeChatTypeorder_by"created_at" | "updated_at"order"desc" | "asc"Return type by call:
withPagination: true→PaginatedResource<Chat>withPagination: false→Pagination<Chat>
show properties (6)hide properties (6)
resultsChat[]requiredshow properties (7)hide properties (7)
idstringrequiredcreated_atstringrequiredcode_idstringrequiredversion_idstring | nullrequiredtitlestring | nullrequiredchat_typeChatTyperequiredtotal_messagesnumberrequiredpagenumberrequiredpage_sizenumberrequiredmorebooleanrequiredWhether more pages follow.
total_observationsnumberrequiredTotal results across all pages.
total_pagesnumberrequiredget
GET /v1/chats/{chat_id}
const result = await client.chats.get(chatId);Arguments:
chatIdstringpathrequiredReturns: Chat
show properties (7)hide properties (7)
idstringrequiredcreated_atstringrequiredcode_idstringrequiredversion_idstring | nullrequiredtitlestring | nullrequiredchat_typeChatTyperequiredtotal_messagesnumberrequiredmessages
GET /v1/chats/{chat_id}/messages
const result = await client.chats.messages(chatId);Arguments:
chatIdstringpathrequiredReturns: ResultsResponse<ChatMessage>
show properties (1)hide properties (1)
resultsChatMessage[]requiredshow properties (8)hide properties (8)
idstringrequiredcreated_atstringrequiredchat_idstringrequiredchat_roleChatMessageRolerequiredmessagestringrequiredrefsInlineRef[]requiredshow properties (6)hide properties (6)
idstringrequiredtypestringrequiredsourcestringrequiredref_indnumberrequirednamestring | nullrequiredis_stalebooleanrequiredhas_proposalbooleanrequiredproposal_status"pending" | "approved" | "rejected" | nullrequiredsync
POST /v1/chats/{chat_id}/sync
Send a message and wait for the full reply.
const result = await client.chats.sync(chatId, body);Arguments:
chatIdstringpathrequiredbodyChatCreateMessageBodybodyrequiredmessagestringrequiredis_retrybooleanapproval_idstringis_approvedbooleanReturns: ChatMessage
show properties (8)hide properties (8)
idstringrequiredcreated_atstringrequiredchat_idstringrequiredchat_roleChatMessageRolerequiredmessagestringrequiredrefsInlineRef[]requiredshow properties (6)hide properties (6)
idstringrequiredtypestringrequiredsourcestringrequiredref_indnumberrequirednamestring | nullrequiredis_stalebooleanrequiredhas_proposalbooleanrequiredproposal_status"pending" | "approved" | "rejected" | nullrequiredsessionToken
POST /v1/chats/{chat_id}/session-token
A single-use token for one chat stream. Generate it server-side.
const result = await client.chats.sessionToken(chatId);Arguments:
chatIdstringpathrequiredReturns: string
stream
POST /v1/chats/{chat_id}/stream
Use session_token() for initial request
Send a message and stream the reply.
for await (const item of client.chats.stream(chatId, sessionToken, body)) {
// ...
}Arguments:
chatIdstringpathrequiredsessionTokenstringbodyrequiredbodyChatCreateStreamMessageBodybodyrequiredmessagestringrequiredis_retrybooleanapproval_idstringis_approvedbooleantokenstringrequiredReturns: AsyncGenerator<ChatMessageStream>
Scoped access
client.chats.with(chatId) returns these methods with chatId already bound.

