diff --git a/api.md b/api.md
index 21eeacfd..71b4e511 100644
--- a/api.md
+++ b/api.md
@@ -13,6 +13,7 @@ Methods:
Types:
- Chat
+- ChatCompletionChunk
Methods:
diff --git a/src/index.ts b/src/index.ts
index 375b22ea..2c9d06ba 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -195,6 +195,7 @@ export namespace Writer {
export import ChatResource = API.ChatResource;
export import Chat = API.Chat;
+ export import ChatCompletionChunk = API.ChatCompletionChunk;
export import ChatChatParams = API.ChatChatParams;
export import ChatChatParamsNonStreaming = API.ChatChatParamsNonStreaming;
export import ChatChatParamsStreaming = API.ChatChatParamsStreaming;
diff --git a/src/resources/chat.ts b/src/resources/chat.ts
index 8d6dd188..ed4654f4 100644
--- a/src/resources/chat.ts
+++ b/src/resources/chat.ts
@@ -13,12 +13,18 @@ export class ChatResource extends APIResource {
* [chat completion guide](/api-guides/chat-completion).
*/
chat(body: ChatChatParamsNonStreaming, options?: Core.RequestOptions): APIPromise;
- chat(body: ChatChatParamsStreaming, options?: Core.RequestOptions): APIPromise>;
- chat(body: ChatChatParamsBase, options?: Core.RequestOptions): APIPromise | Chat>;
- chat(body: ChatChatParams, options?: Core.RequestOptions): APIPromise | APIPromise> {
+ chat(body: ChatChatParamsStreaming, options?: Core.RequestOptions): APIPromise>;
+ chat(
+ body: ChatChatParamsBase,
+ options?: Core.RequestOptions,
+ ): APIPromise | Chat>;
+ chat(
+ body: ChatChatParams,
+ options?: Core.RequestOptions,
+ ): APIPromise | APIPromise> {
return this._client.post('/v1/chat', { body, ...options, stream: body.stream ?? false }) as
| APIPromise
- | APIPromise>;
+ | APIPromise>;
}
}
@@ -279,6 +285,296 @@ export namespace Chat {
}
}
+export interface ChatCompletionChunk {
+ /**
+ * A globally unique identifier (UUID) for the response generated by the API. This
+ * ID can be used to reference the specific operation or transaction within the
+ * system for tracking or debugging purposes.
+ */
+ id: string;
+
+ /**
+ * An array of objects representing the different outcomes or results produced by
+ * the model based on the input provided.
+ */
+ choices: Array;
+
+ /**
+ * The Unix timestamp (in seconds) when the response was created. This timestamp
+ * can be used to verify the timing of the response relative to other events or
+ * operations.
+ */
+ created: number;
+
+ /**
+ * Identifies the specific model used to generate the response.
+ */
+ model: string;
+
+ service_tier?: string;
+
+ system_fingerprint?: string;
+
+ /**
+ * Usage information for the chat completion response. Please note that at this
+ * time Knowledge Graph tool usage is not included in this object.
+ */
+ usage?: ChatCompletionChunk.Usage;
+}
+
+export namespace ChatCompletionChunk {
+ export interface Choice {
+ /**
+ * A chat completion delta generated by streamed model responses.
+ */
+ delta: Choice.Delta;
+
+ /**
+ * The index of the choice in the list of completions generated by the model.
+ */
+ index: number;
+
+ /**
+ * Describes the condition under which the model ceased generating content. Common
+ * reasons include 'length' (reached the maximum output size), 'stop' (encountered
+ * a stop sequence), 'content_filter' (harmful content filtered out), or
+ * 'tool_calls' (encountered tool calls).
+ */
+ finish_reason?: 'stop' | 'length' | 'content_filter' | 'tool_calls';
+
+ /**
+ * Log probability information for the choice.
+ */
+ logprobs?: Choice.Logprobs;
+
+ /**
+ * The chat completion message from the model. Note: this field is deprecated for
+ * streaming. Use `delta` instead.
+ */
+ message?: Choice.Message;
+
+ /**
+ * An array of source objects that provide context for the model's response. Only
+ * returned when using the Knowledge Graph chat tool.
+ */
+ sources?: Array;
+
+ /**
+ * An array of sub-query objects that provide context for the model's response.
+ * Only returned when using the Knowledge Graph chat tool.
+ */
+ subqueries?: Array;
+ }
+
+ export namespace Choice {
+ /**
+ * A chat completion delta generated by streamed model responses.
+ */
+ export interface Delta {
+ /**
+ * Specifies the role associated with the content, indicating whether the message
+ * is from the 'assistant' or another defined role, helping to contextualize the
+ * output within the interaction flow.
+ */
+ role: 'user' | 'assistant' | 'system';
+
+ /**
+ * The text content produced by the model. This field contains the actual output
+ * generated, reflecting the model's response to the input query or command.
+ */
+ content?: string;
+
+ tool_calls?: Array;
+ }
+
+ export namespace Delta {
+ export interface ToolCall {
+ id?: string;
+
+ function?: ToolCall.Function;
+
+ index?: number;
+
+ type?: string;
+ }
+
+ export namespace ToolCall {
+ export interface Function {
+ arguments?: string;
+
+ name?: string;
+ }
+ }
+ }
+
+ /**
+ * Log probability information for the choice.
+ */
+ export interface Logprobs {
+ content?: Array | null;
+
+ refusal?: Array | null;
+ }
+
+ export namespace Logprobs {
+ export interface Content {
+ token: string;
+
+ logprob: number;
+
+ top_logprobs: Array;
+
+ bytes?: Array;
+ }
+
+ export namespace Content {
+ /**
+ * An array of mappings for each token to its top log probabilities, showing
+ * detailed prediction probabilities.
+ */
+ export interface TopLogprob {
+ token: string;
+
+ logprob: number;
+
+ bytes?: Array;
+ }
+ }
+
+ export interface Refusal {
+ token: string;
+
+ logprob: number;
+
+ top_logprobs: Array;
+
+ bytes?: Array;
+ }
+
+ export namespace Refusal {
+ /**
+ * An array of mappings for each token to its top log probabilities, showing
+ * detailed prediction probabilities.
+ */
+ export interface TopLogprob {
+ token: string;
+
+ logprob: number;
+
+ bytes?: Array;
+ }
+ }
+ }
+
+ /**
+ * The chat completion message from the model. Note: this field is deprecated for
+ * streaming. Use `delta` instead.
+ */
+ export interface Message {
+ /**
+ * Specifies the role associated with the content, indicating whether the message
+ * is from the 'assistant' or another defined role, helping to contextualize the
+ * output within the interaction flow.
+ */
+ role: 'user' | 'assistant' | 'system';
+
+ /**
+ * The text content produced by the model. This field contains the actual output
+ * generated, reflecting the model's response to the input query or command.
+ */
+ content?: string;
+
+ tool_calls?: Array;
+ }
+
+ export namespace Message {
+ export interface ToolCall {
+ id?: string;
+
+ function?: ToolCall.Function;
+
+ index?: number;
+
+ type?: string;
+ }
+
+ export namespace ToolCall {
+ export interface Function {
+ arguments?: string;
+
+ name?: string;
+ }
+ }
+ }
+
+ export interface Source {
+ /**
+ * The unique identifier of the file.
+ */
+ file_id: string;
+
+ /**
+ * A snippet of text from the source file.
+ */
+ snippet: string;
+ }
+
+ export interface Subquery {
+ /**
+ * The answer to the subquery.
+ */
+ answer: string;
+
+ /**
+ * The subquery that was asked.
+ */
+ query: string;
+
+ sources: Array;
+ }
+
+ export namespace Subquery {
+ export interface Source {
+ /**
+ * The unique identifier of the file.
+ */
+ file_id: string;
+
+ /**
+ * A snippet of text from the source file.
+ */
+ snippet: string;
+ }
+ }
+ }
+
+ /**
+ * Usage information for the chat completion response. Please note that at this
+ * time Knowledge Graph tool usage is not included in this object.
+ */
+ export interface Usage {
+ completion_tokens: number;
+
+ prompt_tokens: number;
+
+ total_tokens: number;
+
+ completion_tokens_details?: Usage.CompletionTokensDetails;
+
+ prompt_token_details?: Usage.PromptTokenDetails;
+ }
+
+ export namespace Usage {
+ export interface CompletionTokensDetails {
+ reasoning_tokens: number;
+ }
+
+ export interface PromptTokenDetails {
+ cached_tokens: number;
+ }
+ }
+}
+
export type ChatChatParams = ChatChatParamsNonStreaming | ChatChatParamsStreaming;
export interface ChatChatParamsBase {
@@ -451,6 +747,7 @@ export interface ChatChatParamsStreaming extends ChatChatParamsBase {
export namespace ChatResource {
export import Chat = ChatAPI.Chat;
+ export import ChatCompletionChunk = ChatAPI.ChatCompletionChunk;
export import ChatChatParams = ChatAPI.ChatChatParams;
export import ChatChatParamsNonStreaming = ChatAPI.ChatChatParamsNonStreaming;
export import ChatChatParamsStreaming = ChatAPI.ChatChatParamsStreaming;
diff --git a/src/resources/index.ts b/src/resources/index.ts
index d943e6f8..d6fdbefd 100644
--- a/src/resources/index.ts
+++ b/src/resources/index.ts
@@ -7,6 +7,7 @@ export {
} from './applications';
export {
Chat,
+ ChatCompletionChunk,
ChatChatParams,
ChatChatParamsNonStreaming,
ChatChatParamsStreaming,