@@ -183,8 +183,9 @@ export interface ChatCompletionChunk {
183
183
id : string ;
184
184
185
185
/**
186
- * A list of chat completion choices. Can be more than one if `n` is greater
187
- * than 1.
186
+ * A list of chat completion choices. Can contain more than one elements if `n` is
187
+ * greater than 1. Can also be empty for the last chunk if you set
188
+ * `stream_options: {"include_usage": true}`.
188
189
*/
189
190
choices : Array < ChatCompletionChunk . Choice > ;
190
191
@@ -210,6 +211,14 @@ export interface ChatCompletionChunk {
210
211
* backend changes have been made that might impact determinism.
211
212
*/
212
213
system_fingerprint ?: string ;
214
+
215
+ /**
216
+ * An optional field that will only be present when you set
217
+ * `stream_options: {"include_usage": true}` in your request. When present, it
218
+ * contains a null value except for the last chunk which contains the token usage
219
+ * statistics for the entire request.
220
+ */
221
+ usage ?: CompletionsAPI . CompletionUsage ;
213
222
}
214
223
215
224
export namespace ChatCompletionChunk {
@@ -517,6 +526,19 @@ export namespace ChatCompletionNamedToolChoice {
517
526
*/
518
527
export type ChatCompletionRole = 'system' | 'user' | 'assistant' | 'tool' | 'function' ;
519
528
529
+ /**
530
+ * Options for streaming response. Only set this when you set `stream: true`.
531
+ */
532
+ export interface ChatCompletionStreamOptions {
533
+ /**
534
+ * If set, an additional chunk will be streamed before the `data: [DONE]` message.
535
+ * The `usage` field on this chunk shows the token usage statistics for the entire
536
+ * request, and the `choices` field will always be an empty array. All other chunks
537
+ * will also include a `usage` field, but with a null value.
538
+ */
539
+ include_usage ?: boolean ;
540
+ }
541
+
520
542
export interface ChatCompletionSystemMessageParam {
521
543
/**
522
544
* The contents of the system message.
@@ -786,6 +808,11 @@ export interface ChatCompletionCreateParamsBase {
786
808
*/
787
809
stream ?: boolean | null ;
788
810
811
+ /**
812
+ * Options for streaming response. Only set this when you set `stream: true`.
813
+ */
814
+ stream_options ?: ChatCompletionStreamOptions | null ;
815
+
789
816
/**
790
817
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
791
818
* make the output more random, while lower values like 0.2 will make it more
@@ -949,6 +976,7 @@ export namespace Completions {
949
976
export import ChatCompletionMessageToolCall = ChatCompletionsAPI . ChatCompletionMessageToolCall ;
950
977
export import ChatCompletionNamedToolChoice = ChatCompletionsAPI . ChatCompletionNamedToolChoice ;
951
978
export import ChatCompletionRole = ChatCompletionsAPI . ChatCompletionRole ;
979
+ export import ChatCompletionStreamOptions = ChatCompletionsAPI . ChatCompletionStreamOptions ;
952
980
export import ChatCompletionSystemMessageParam = ChatCompletionsAPI . ChatCompletionSystemMessageParam ;
953
981
export import ChatCompletionTokenLogprob = ChatCompletionsAPI . ChatCompletionTokenLogprob ;
954
982
export import ChatCompletionTool = ChatCompletionsAPI . ChatCompletionTool ;
0 commit comments