async_openai_compat/types/
chat.rs

1use std::{collections::HashMap, pin::Pin};
2
3use derive_builder::Builder;
4use futures::Stream;
5use serde::{Deserialize, Serialize};
6
7use crate::error::OpenAIError;
8
9#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
10#[serde(untagged)]
11pub enum Prompt {
12    String(String),
13    StringArray(Vec<String>),
14    // Minimum value is 0, maximum value is 4_294_967_295 (inclusive).
15    IntegerArray(Vec<u32>),
16    ArrayOfIntegerArray(Vec<Vec<u32>>),
17}
18
19#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
20#[serde(untagged)]
21pub enum Stop {
22    String(String),           // nullable: true
23    StringArray(Vec<String>), // minItems: 1; maxItems: 4
24}
25
26#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
27pub struct Logprobs {
28    pub tokens: Vec<String>,
29    pub token_logprobs: Vec<Option<f32>>, // Option is to account for null value in the list
30    pub top_logprobs: Vec<serde_json::Value>,
31    pub text_offset: Vec<u32>,
32}
33
34#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
35#[serde(rename_all = "snake_case")]
36pub enum CompletionFinishReason {
37    Stop,
38    Length,
39    ContentFilter,
40}
41
42#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
43pub struct Choice {
44    pub text: String,
45    pub index: u32,
46    pub logprobs: Option<Logprobs>,
47    pub finish_reason: Option<CompletionFinishReason>,
48}
49
50#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
51pub enum ChatCompletionFunctionCall {
52    /// The model does not call a function, and responds to the end-user.
53    #[serde(rename = "none")]
54    None,
55    /// The model can pick between an end-user or calling a function.
56    #[serde(rename = "auto")]
57    Auto,
58
59    // In spec this is ChatCompletionFunctionCallOption
60    // based on feedback from @m1guelpf in https://github.com/64bit/async-openai/pull/118
61    // it is diverged from the spec
62    /// Forces the model to call the specified function.
63    #[serde(untagged)]
64    Function { name: String },
65}
66
67#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq)]
68#[serde(rename_all = "lowercase")]
69pub enum Role {
70    System,
71    #[default]
72    User,
73    Assistant,
74    Tool,
75    Function,
76}
77
78/// The name and arguments of a function that should be called, as generated by the model.
79#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
80pub struct FunctionCall {
81    /// The name of the function to call.
82    pub name: String,
83    /// The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
84    pub arguments: String,
85}
86
87/// Usage statistics for the completion request.
88#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default)]
89pub struct CompletionUsage {
90    /// Number of tokens in the prompt.
91    pub prompt_tokens: u32,
92    /// Number of tokens in the generated completion.
93    pub completion_tokens: u32,
94    /// Total number of tokens used in the request (prompt + completion).
95    pub total_tokens: u32,
96    /// Breakdown of tokens used in the prompt.
97    pub prompt_tokens_details: Option<PromptTokensDetails>,
98    /// Breakdown of tokens used in a completion.
99    pub completion_tokens_details: Option<CompletionTokensDetails>,
100}
101
102/// Breakdown of tokens used in a completion.
103#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default)]
104pub struct PromptTokensDetails {
105    /// Audio input tokens present in the prompt.
106    #[serde(skip_serializing_if = "Option::is_none")]
107    pub audio_tokens: Option<u32>,
108    /// Cached tokens present in the prompt.
109    #[serde(skip_serializing_if = "Option::is_none")]
110    pub cached_tokens: Option<u32>,
111}
112
113/// Breakdown of tokens used in a completion.
114#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default)]
115pub struct CompletionTokensDetails {
116    #[serde(skip_serializing_if = "Option::is_none")]
117    pub accepted_prediction_tokens: Option<u32>,
118    /// Audio input tokens generated by the model.
119    #[serde(skip_serializing_if = "Option::is_none")]
120    pub audio_tokens: Option<u32>,
121    /// Tokens generated by the model for reasoning.
122    #[serde(skip_serializing_if = "Option::is_none")]
123    pub reasoning_tokens: Option<u32>,
124    ///  When using Predicted Outputs, the number of tokens in the
125    /// prediction that did not appear in the completion. However, like
126    /// reasoning tokens, these tokens are still counted in the total
127    /// completion tokens for purposes of billing, output, and context
128    /// window limits.
129    #[serde(skip_serializing_if = "Option::is_none")]
130    pub rejected_prediction_tokens: Option<u32>,
131}
132
133#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
134#[builder(name = "ChatCompletionRequestDeveloperMessageArgs")]
135#[builder(pattern = "mutable")]
136#[builder(setter(into, strip_option), default)]
137#[builder(derive(Debug))]
138#[builder(build_fn(error = "OpenAIError"))]
139pub struct ChatCompletionRequestDeveloperMessage {
140    /// The contents of the developer message.
141    pub content: ChatCompletionRequestDeveloperMessageContent,
142
143    /// An optional name for the participant. Provides the model information to differentiate between participants of the same role.
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub name: Option<String>,
146}
147
148#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
149#[serde(untagged)]
150pub enum ChatCompletionRequestDeveloperMessageContent {
151    Text(String),
152    Array(Vec<ChatCompletionRequestMessageContentPartText>),
153}
154
155#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
156#[builder(name = "ChatCompletionRequestSystemMessageArgs")]
157#[builder(pattern = "mutable")]
158#[builder(setter(into, strip_option), default)]
159#[builder(derive(Debug))]
160#[builder(build_fn(error = "OpenAIError"))]
161pub struct ChatCompletionRequestSystemMessage {
162    /// The contents of the system message.
163    pub content: ChatCompletionRequestSystemMessageContent,
164    /// An optional name for the participant. Provides the model information to differentiate between participants of the same role.
165    #[serde(skip_serializing_if = "Option::is_none")]
166    pub name: Option<String>,
167}
168
169#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
170#[builder(name = "ChatCompletionRequestMessageContentPartTextArgs")]
171#[builder(pattern = "mutable")]
172#[builder(setter(into, strip_option), default)]
173#[builder(derive(Debug))]
174#[builder(build_fn(error = "OpenAIError"))]
175pub struct ChatCompletionRequestMessageContentPartText {
176    pub text: String,
177}
178
179#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
180pub struct ChatCompletionRequestMessageContentPartRefusal {
181    /// The refusal message generated by the model.
182    pub refusal: String,
183}
184
185#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq)]
186#[serde(rename_all = "lowercase")]
187pub enum ImageDetail {
188    #[default]
189    Auto,
190    Low,
191    High,
192}
193
194#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
195#[builder(name = "ImageUrlArgs")]
196#[builder(pattern = "mutable")]
197#[builder(setter(into, strip_option), default)]
198#[builder(derive(Debug))]
199#[builder(build_fn(error = "OpenAIError"))]
200pub struct ImageUrl {
201    /// Either a URL of the image or the base64 encoded image data.
202    pub url: String,
203    /// Specifies the detail level of the image. Learn more in the [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).
204    pub detail: Option<ImageDetail>,
205}
206
207#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
208#[builder(name = "ChatCompletionRequestMessageContentPartImageArgs")]
209#[builder(pattern = "mutable")]
210#[builder(setter(into, strip_option), default)]
211#[builder(derive(Debug))]
212#[builder(build_fn(error = "OpenAIError"))]
213pub struct ChatCompletionRequestMessageContentPartImage {
214    pub image_url: ImageUrl,
215}
216
217#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq)]
218#[serde(rename_all = "lowercase")]
219pub enum InputAudioFormat {
220    Wav,
221    #[default]
222    Mp3,
223}
224
225#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq)]
226pub struct InputAudio {
227    /// Base64 encoded audio data.
228    pub data: String,
229    /// The format of the encoded audio data. Currently supports "wav" and "mp3".
230    pub format: InputAudioFormat,
231}
232
233/// Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
234#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
235#[builder(name = "ChatCompletionRequestMessageContentPartAudioArgs")]
236#[builder(pattern = "mutable")]
237#[builder(setter(into, strip_option), default)]
238#[builder(derive(Debug))]
239#[builder(build_fn(error = "OpenAIError"))]
240pub struct ChatCompletionRequestMessageContentPartAudio {
241    pub input_audio: InputAudio,
242}
243
244#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
245#[serde(tag = "type")]
246#[serde(rename_all = "snake_case")]
247pub enum ChatCompletionRequestUserMessageContentPart {
248    Text(ChatCompletionRequestMessageContentPartText),
249    ImageUrl(ChatCompletionRequestMessageContentPartImage),
250    InputAudio(ChatCompletionRequestMessageContentPartAudio),
251}
252
253#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
254#[serde(tag = "type")]
255#[serde(rename_all = "snake_case")]
256pub enum ChatCompletionRequestSystemMessageContentPart {
257    Text(ChatCompletionRequestMessageContentPartText),
258}
259
260#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
261#[serde(tag = "type")]
262#[serde(rename_all = "snake_case")]
263pub enum ChatCompletionRequestAssistantMessageContentPart {
264    Text(ChatCompletionRequestMessageContentPartText),
265    Refusal(ChatCompletionRequestMessageContentPartRefusal),
266}
267
268#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
269#[serde(tag = "type")]
270#[serde(rename_all = "snake_case")]
271pub enum ChatCompletionRequestToolMessageContentPart {
272    Text(ChatCompletionRequestMessageContentPartText),
273}
274
275#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
276#[serde(untagged)]
277pub enum ChatCompletionRequestSystemMessageContent {
278    /// The text contents of the system message.
279    Text(String),
280    /// An array of content parts with a defined type. For system messages, only type `text` is supported.
281    Array(Vec<ChatCompletionRequestSystemMessageContentPart>),
282}
283
284#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
285#[serde(untagged)]
286pub enum ChatCompletionRequestUserMessageContent {
287    /// The text contents of the message.
288    Text(String),
289    /// An array of content parts with a defined type. Supported options differ based on the [model](https://platform.openai.com/docs/models) being used to generate the response. Can contain text, image, or audio inputs.
290    Array(Vec<ChatCompletionRequestUserMessageContentPart>),
291}
292
293#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
294#[serde(untagged)]
295pub enum ChatCompletionRequestAssistantMessageContent {
296    /// The text contents of the message.
297    Text(String),
298    /// An array of content parts with a defined type. Can be one or more of type `text`, or exactly one of type `refusal`.
299    Array(Vec<ChatCompletionRequestAssistantMessageContentPart>),
300}
301
302#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
303#[serde(untagged)]
304pub enum ChatCompletionRequestToolMessageContent {
305    /// The text contents of the tool message.
306    Text(String),
307    /// An array of content parts with a defined type. For tool messages, only type `text` is supported.
308    Array(Vec<ChatCompletionRequestToolMessageContentPart>),
309}
310
311#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
312#[builder(name = "ChatCompletionRequestUserMessageArgs")]
313#[builder(pattern = "mutable")]
314#[builder(setter(into, strip_option), default)]
315#[builder(derive(Debug))]
316#[builder(build_fn(error = "OpenAIError"))]
317pub struct ChatCompletionRequestUserMessage {
318    /// The contents of the user message.
319    pub content: ChatCompletionRequestUserMessageContent,
320    /// An optional name for the participant. Provides the model information to differentiate between participants of the same role.
321    #[serde(skip_serializing_if = "Option::is_none")]
322    pub name: Option<String>,
323}
324
325#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq)]
326pub struct ChatCompletionRequestAssistantMessageAudio {
327    /// Unique identifier for a previous audio response from the model.
328    pub id: String,
329}
330
331#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
332#[builder(name = "ChatCompletionRequestAssistantMessageArgs")]
333#[builder(pattern = "mutable")]
334#[builder(setter(into, strip_option), default)]
335#[builder(derive(Debug))]
336#[builder(build_fn(error = "OpenAIError"))]
337pub struct ChatCompletionRequestAssistantMessage {
338    /// The contents of the assistant message. Required unless `tool_calls` or `function_call` is specified.
339    #[serde(skip_serializing_if = "Option::is_none")]
340    pub content: Option<ChatCompletionRequestAssistantMessageContent>,
341    /// The refusal message by the assistant.
342    #[serde(skip_serializing_if = "Option::is_none")]
343    pub refusal: Option<String>,
344    /// An optional name for the participant. Provides the model information to differentiate between participants of the same role.
345    #[serde(skip_serializing_if = "Option::is_none")]
346    pub name: Option<String>,
347    /// Data about a previous audio response from the model.
348    /// [Learn more](https://platform.openai.com/docs/guides/audio).
349    #[serde(skip_serializing_if = "Option::is_none")]
350    pub audio: Option<ChatCompletionRequestAssistantMessageAudio>,
351    #[serde(skip_serializing_if = "Option::is_none")]
352    pub tool_calls: Option<Vec<ChatCompletionMessageToolCall>>,
353    /// Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model.
354    #[deprecated]
355    #[serde(skip_serializing_if = "Option::is_none")]
356    pub function_call: Option<FunctionCall>,
357}
358
359/// Tool message
360#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
361#[builder(name = "ChatCompletionRequestToolMessageArgs")]
362#[builder(pattern = "mutable")]
363#[builder(setter(into, strip_option), default)]
364#[builder(derive(Debug))]
365#[builder(build_fn(error = "OpenAIError"))]
366pub struct ChatCompletionRequestToolMessage {
367    /// The contents of the tool message.
368    pub content: ChatCompletionRequestToolMessageContent,
369    pub tool_call_id: String,
370}
371
372#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]
373#[builder(name = "ChatCompletionRequestFunctionMessageArgs")]
374#[builder(pattern = "mutable")]
375#[builder(setter(into, strip_option), default)]
376#[builder(derive(Debug))]
377#[builder(build_fn(error = "OpenAIError"))]
378pub struct ChatCompletionRequestFunctionMessage {
379    /// The return value from the function call, to return to the model.
380    pub content: Option<String>,
381    /// The name of the function to call.
382    pub name: String,
383}
384
385#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
386#[serde(tag = "role")]
387#[serde(rename_all = "lowercase")]
388pub enum ChatCompletionRequestMessage {
389    Developer(ChatCompletionRequestDeveloperMessage),
390    System(ChatCompletionRequestSystemMessage),
391    User(ChatCompletionRequestUserMessage),
392    Assistant(ChatCompletionRequestAssistantMessage),
393    Tool(ChatCompletionRequestToolMessage),
394    Function(ChatCompletionRequestFunctionMessage),
395}
396
397#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
398pub struct ChatCompletionMessageToolCall {
399    /// The ID of the tool call.
400    pub id: String,
401    /// The type of the tool. Currently, only `function` is supported.
402    pub r#type: ChatCompletionToolType,
403    /// The function that the model called.
404    pub function: FunctionCall,
405}
406
407#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq)]
408pub struct ChatCompletionResponseMessageAudio {
409    /// Unique identifier for this audio response.
410    pub id: String,
411    /// The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.
412    pub expires_at: u32,
413    /// Base64 encoded audio bytes generated by the model, in the format specified in the request.
414    pub data: String,
415    /// Transcript of the audio generated by the model.
416    pub transcript: String,
417}
418
419/// A chat completion message generated by the model.
420#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
421pub struct ChatCompletionResponseMessage {
422    /// The contents of the message.
423    pub content: Option<String>,
424    /// The refusal message generated by the model.
425    pub refusal: Option<String>,
426    /// The tool calls generated by the model, such as function calls.
427    pub tool_calls: Option<Vec<ChatCompletionMessageToolCall>>,
428
429    /// The role of the author of this message.
430    pub role: Role,
431
432    /// Deprecated and replaced by `tool_calls`.
433    /// The name and arguments of a function that should be called, as generated by the model.
434    #[deprecated]
435    pub function_call: Option<FunctionCall>,
436
437    /// If the audio output modality is requested, this object contains data about the audio response from the model. [Learn more](https://platform.openai.com/docs/guides/audio).
438    pub audio: Option<ChatCompletionResponseMessageAudio>,
439}
440
441#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
442#[builder(name = "ChatCompletionFunctionsArgs")]
443#[builder(pattern = "mutable")]
444#[builder(setter(into, strip_option), default)]
445#[builder(derive(Debug))]
446#[builder(build_fn(error = "OpenAIError"))]
447#[deprecated]
448pub struct ChatCompletionFunctions {
449    /// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
450    pub name: String,
451    /// A description of what the function does, used by the model to choose when and how to call the function.
452    #[serde(skip_serializing_if = "Option::is_none")]
453    pub description: Option<String>,
454    /// The parameters the functions accepts, described as a JSON Schema object. See the [guide](https://platform.openai.com/docs/guides/text-generation/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format.
455    ///
456    /// Omitting `parameters` defines a function with an empty parameter list.
457    pub parameters: serde_json::Value,
458}
459
460#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
461#[builder(name = "FunctionObjectArgs")]
462#[builder(pattern = "mutable")]
463#[builder(setter(into, strip_option), default)]
464#[builder(derive(Debug))]
465#[builder(build_fn(error = "OpenAIError"))]
466pub struct FunctionObject {
467    /// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
468    pub name: String,
469    /// A description of what the function does, used by the model to choose when and how to call the function.
470    #[serde(skip_serializing_if = "Option::is_none")]
471    pub description: Option<String>,
472    /// The parameters the functions accepts, described as a JSON Schema object. See the [guide](https://platform.openai.com/docs/guides/text-generation/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format.
473    ///
474    /// Omitting `parameters` defines a function with an empty parameter list.
475    #[serde(skip_serializing_if = "Option::is_none")]
476    pub parameters: Option<serde_json::Value>,
477
478    /// Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the `parameters` field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn more about Structured Outputs in the [function calling guide](https://platform.openai.com/docs/guides/function-calling).
479    #[serde(skip_serializing_if = "Option::is_none")]
480    pub strict: Option<bool>,
481}
482
483#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
484#[serde(tag = "type", rename_all = "snake_case")]
485pub enum ResponseFormat {
486    /// The type of response format being defined: `text`
487    Text,
488    /// The type of response format being defined: `json_object`
489    JsonObject,
490    /// The type of response format being defined: `json_schema`
491    JsonSchema {
492        json_schema: ResponseFormatJsonSchema,
493    },
494}
495
496#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
497pub struct ResponseFormatJsonSchema {
498    /// A description of what the response format is for, used by the model to determine how to respond in the format.
499    #[serde(skip_serializing_if = "Option::is_none")]
500    pub description: Option<String>,
501    /// The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
502    pub name: String,
503    /// The schema for the response format, described as a JSON Schema object.
504    #[serde(skip_serializing_if = "Option::is_none")]
505    pub schema: Option<serde_json::Value>,
506    /// Whether to enable strict schema adherence when generating the output. If set to true, the model will always follow the exact schema defined in the `schema` field. Only a subset of JSON Schema is supported when `strict` is `true`. To learn more, read the [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
507    #[serde(skip_serializing_if = "Option::is_none")]
508    pub strict: Option<bool>,
509}
510
511#[derive(Clone, Serialize, Default, Debug, Deserialize, PartialEq)]
512#[serde(rename_all = "lowercase")]
513pub enum ChatCompletionToolType {
514    #[default]
515    Function,
516}
517
518#[derive(Clone, Serialize, Default, Debug, Builder, Deserialize, PartialEq)]
519#[builder(name = "ChatCompletionToolArgs")]
520#[builder(pattern = "mutable")]
521#[builder(setter(into, strip_option), default)]
522#[builder(derive(Debug))]
523#[builder(build_fn(error = "OpenAIError"))]
524pub struct ChatCompletionTool {
525    #[builder(default = "ChatCompletionToolType::Function")]
526    pub r#type: ChatCompletionToolType,
527    pub function: FunctionObject,
528}
529
530#[derive(Clone, Serialize, Default, Debug, Deserialize, PartialEq)]
531pub struct FunctionName {
532    /// The name of the function to call.
533    pub name: String,
534}
535
536/// Specifies a tool the model should use. Use to force the model to call a specific function.
537#[derive(Clone, Serialize, Default, Debug, Deserialize, PartialEq)]
538pub struct ChatCompletionNamedToolChoice {
539    /// The type of the tool. Currently, only `function` is supported.
540    pub r#type: ChatCompletionToolType,
541
542    pub function: FunctionName,
543}
544
545/// Controls which (if any) tool is called by the model.
546/// `none` means the model will not call any tool and instead generates a message.
547/// `auto` means the model can pick between generating a message or calling one or more tools.
548/// `required` means the model must call one or more tools.
549/// Specifying a particular tool via `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool.
550///
551/// `none` is the default when no tools are present. `auto` is the default if tools are present.present.
552#[derive(Clone, Serialize, Default, Debug, Deserialize, PartialEq)]
553#[serde(rename_all = "lowercase")]
554pub enum ChatCompletionToolChoiceOption {
555    #[default]
556    None,
557    Auto,
558    Required,
559    #[serde(untagged)]
560    Named(ChatCompletionNamedToolChoice),
561}
562
563#[derive(Clone, Serialize, Debug, Deserialize, PartialEq, Default)]
564#[serde(rename_all = "lowercase")]
565/// The amount of context window space to use for the search.
566pub enum WebSearchContextSize {
567    Low,
568    #[default]
569    Medium,
570    High,
571}
572
573#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
574#[serde(rename_all = "lowercase")]
575pub enum WebSearchUserLocationType {
576    Approximate,
577}
578
579/// Approximate location parameters for the search.
580#[derive(Clone, Serialize, Debug, Default, Deserialize, PartialEq)]
581pub struct WebSearchLocation {
582    ///  The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of the user, e.g. `US`.
583    pub country: Option<String>,
584    /// Free text input for the region of the user, e.g. `California`.
585    pub region: Option<String>,
586    /// Free text input for the city of the user, e.g. `San Francisco`.
587    pub city: Option<String>,
588    /// The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the user, e.g. `America/Los_Angeles`.
589    pub timezone: Option<String>,
590}
591
592#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
593pub struct WebSearchUserLocation {
594    //  The type of location approximation. Always `approximate`.
595    pub r#type: WebSearchUserLocationType,
596
597    pub approximate: WebSearchLocation,
598}
599
600/// Options for the web search tool.
601#[derive(Clone, Serialize, Debug, Default, Deserialize, PartialEq)]
602pub struct WebSearchOptions {
603    /// High level guidance for the amount of context window space to use for the search. One of `low`, `medium`, or `high`. `medium` is the default.
604    pub search_context_size: Option<WebSearchContextSize>,
605
606    /// Approximate location parameters for the search.
607    pub user_location: Option<WebSearchUserLocation>,
608}
609
610#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
611#[serde(rename_all = "lowercase")]
612pub enum ServiceTier {
613    Auto,
614    Default,
615    Flex,
616}
617
618#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
619#[serde(rename_all = "lowercase")]
620pub enum ServiceTierResponse {
621    Scale,
622    Default,
623    Flex,
624}
625
626#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
627#[serde(rename_all = "lowercase")]
628pub enum ReasoningEffort {
629    Low,
630    Medium,
631    High,
632}
633
634/// Output types that you would like the model to generate for this request.
635///
636/// Most models are capable of generating text, which is the default: `["text"]`
637///
638/// The `gpt-4o-audio-preview` model can also be used to [generate
639/// audio](https://platform.openai.com/docs/guides/audio). To request that this model generate both text and audio responses, you can use: `["text", "audio"]`
640#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
641#[serde(rename_all = "lowercase")]
642pub enum ChatCompletionModalities {
643    Text,
644    Audio,
645}
646
647/// The content that should be matched when generating a model response. If generated tokens would match this content, the entire model response can be returned much more quickly.
648#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
649#[serde(untagged)]
650pub enum PredictionContentContent {
651    /// The content used for a Predicted Output. This is often the text of a file you are regenerating with minor changes.
652    Text(String),
653    /// An array of content parts with a defined type. Supported options differ based on the [model](https://platform.openai.com/docs/models) being used to generate the response. Can contain text inputs.
654    Array(Vec<ChatCompletionRequestMessageContentPartText>),
655}
656
657/// Static predicted output content, such as the content of a text file that is being regenerated.
658#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
659#[serde(tag = "type", rename_all = "lowercase", content = "content")]
660pub enum PredictionContent {
661    /// The type of the predicted content you want to provide. This type is
662    /// currently always `content`.
663    Content(PredictionContentContent),
664}
665
666#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
667#[serde(rename_all = "lowercase")]
668pub enum ChatCompletionAudioVoice {
669    Alloy,
670    Ash,
671    Ballad,
672    Coral,
673    Echo,
674    Sage,
675    Shimmer,
676    Verse,
677}
678
679#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
680#[serde(rename_all = "lowercase")]
681pub enum ChatCompletionAudioFormat {
682    Wav,
683    Mp3,
684    Flac,
685    Opus,
686    Pcm16,
687}
688
689#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
690pub struct ChatCompletionAudio {
691    /// The voice the model uses to respond. Supported voices are `ash`, `ballad`, `coral`, `sage`, and `verse` (also supported but not recommended are `alloy`, `echo`, and `shimmer`; these voices are less expressive).
692    pub voice: ChatCompletionAudioVoice,
693    /// Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`, or `pcm16`.
694    pub format: ChatCompletionAudioFormat,
695}
696
697#[derive(Clone, Serialize, Default, Debug, Builder, Deserialize, PartialEq)]
698#[builder(name = "CreateChatCompletionRequestArgs")]
699#[builder(pattern = "mutable")]
700#[builder(setter(into, strip_option), default)]
701#[builder(derive(Debug))]
702#[builder(build_fn(error = "OpenAIError"))]
703pub struct CreateChatCompletionRequest {
704    /// A list of messages comprising the conversation so far. Depending on the [model](https://platform.openai.com/docs/models) you use, different message types (modalities) are supported, like [text](https://platform.openai.com/docs/guides/text-generation), [images](https://platform.openai.com/docs/guides/vision), and [audio](https://platform.openai.com/docs/guides/audio).
705    pub messages: Vec<ChatCompletionRequestMessage>, // min: 1
706
707    /// ID of the model to use.
708    /// See the [model endpoint compatibility](https://platform.openai.com/docs/models#model-endpoint-compatibility) table for details on which models work with the Chat API.
709    pub model: String,
710
711    /// Whether or not to store the output of this chat completion request
712    ///
713    /// for use in our [model distillation](https://platform.openai.com/docs/guides/distillation) or [evals](https://platform.openai.com/docs/guides/evals) products.
714    #[serde(skip_serializing_if = "Option::is_none")]
715    pub store: Option<bool>, // nullable: true, default: false
716
717    /// **o1 models only**
718    ///
719    /// Constrains effort on reasoning for
720    /// [reasoning models](https://platform.openai.com/docs/guides/reasoning).
721    ///
722    /// Currently supported values are `low`, `medium`, and `high`. Reducing
723    ///
724    /// reasoning effort can result in faster responses and fewer tokens
725    /// used on reasoning in a response.
726    #[serde(skip_serializing_if = "Option::is_none")]
727    pub reasoning_effort: Option<ReasoningEffort>,
728
729    ///  Developer-defined tags and values used for filtering completions in the [dashboard](https://platform.openai.com/chat-completions).
730    #[serde(skip_serializing_if = "Option::is_none")]
731    pub metadata: Option<serde_json::Value>, // nullable: true
732
733    /// Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
734    #[serde(skip_serializing_if = "Option::is_none")]
735    pub frequency_penalty: Option<f32>, // min: -2.0, max: 2.0, default: 0
736
737    /// Modify the likelihood of specified tokens appearing in the completion.
738    ///
739    /// Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100.
740    /// Mathematically, the bias is added to the logits generated by the model prior to sampling.
741    /// The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection;
742    /// values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
743    #[serde(skip_serializing_if = "Option::is_none")]
744    pub logit_bias: Option<HashMap<String, serde_json::Value>>, // default: null
745
746    /// Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the `content` of `message`.
747    #[serde(skip_serializing_if = "Option::is_none")]
748    pub logprobs: Option<bool>,
749
750    /// An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. `logprobs` must be set to `true` if this parameter is used.
751    #[serde(skip_serializing_if = "Option::is_none")]
752    pub top_logprobs: Option<u8>,
753
754    /// The maximum number of [tokens](https://platform.openai.com/tokenizer) that can be generated in the chat completion.
755    ///
756    /// This value can be used to control [costs](https://openai.com/api/pricing/) for text generated via API.
757    /// This value is now deprecated in favor of `max_completion_tokens`, and is
758    /// not compatible with [o1 series models](https://platform.openai.com/docs/guides/reasoning).
759    #[deprecated]
760    #[serde(skip_serializing_if = "Option::is_none")]
761    pub max_tokens: Option<u32>,
762
763    /// An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
764    #[serde(skip_serializing_if = "Option::is_none")]
765    pub max_completion_tokens: Option<u32>,
766
767    /// How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs.
768    #[serde(skip_serializing_if = "Option::is_none")]
769    pub n: Option<u8>, // min:1, max: 128, default: 1
770
771    #[serde(skip_serializing_if = "Option::is_none")]
772    pub modalities: Option<Vec<ChatCompletionModalities>>,
773
774    /// Configuration for a [Predicted Output](https://platform.openai.com/docs/guides/predicted-outputs),which can greatly improve response times when large parts of the model response are known ahead of time. This is most common when you are regenerating a file with only minor changes to most of the content.
775    #[serde(skip_serializing_if = "Option::is_none")]
776    pub prediction: Option<PredictionContent>,
777
778    /// Parameters for audio output. Required when audio output is requested with `modalities: ["audio"]`. [Learn more](https://platform.openai.com/docs/guides/audio).
779    #[serde(skip_serializing_if = "Option::is_none")]
780    pub audio: Option<ChatCompletionAudio>,
781
782    /// Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
783    #[serde(skip_serializing_if = "Option::is_none")]
784    pub presence_penalty: Option<f32>, // min: -2.0, max: 2.0, default 0
785
786    /// An object specifying the format that the model must output. Compatible with [GPT-4o](https://platform.openai.com/docs/models/gpt-4o), [GPT-4o mini](https://platform.openai.com/docs/models/gpt-4o-mini), [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo) and all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`.
787    ///
788    /// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which guarantees the model will match your supplied JSON schema. Learn more in the [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
789    ///
790    /// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is valid JSON.
791    ///
792    /// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.
793    #[serde(skip_serializing_if = "Option::is_none")]
794    pub response_format: Option<ResponseFormat>,
795
796    ///  This feature is in Beta.
797    /// If specified, our system will make a best effort to sample deterministically, such that repeated requests
798    /// with the same `seed` and parameters should return the same result.
799    /// Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
800    #[serde(skip_serializing_if = "Option::is_none")]
801    pub seed: Option<i64>,
802
803    /// Specifies the latency tier to use for processing the request. This parameter is relevant for customers subscribed to the scale tier service:
804    /// - If set to 'auto', the system will utilize scale tier credits until they are exhausted.
805    /// - If set to 'default', the request will be processed using the default service tier with a lower uptime SLA and no latency guarentee.
806    /// - When not set, the default behavior is 'auto'.
807    ///
808    /// When this parameter is set, the response body will include the `service_tier` utilized.
809    #[serde(skip_serializing_if = "Option::is_none")]
810    pub service_tier: Option<ServiceTier>,
811
812    /// Up to 4 sequences where the API will stop generating further tokens.
813    #[serde(skip_serializing_if = "Option::is_none")]
814    pub stop: Option<Stop>,
815
816    /// If set, partial message deltas will be sent, like in ChatGPT.
817    /// Tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
818    /// as they become available, with the stream terminated by a `data: [DONE]` message. [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
819    #[serde(skip_serializing_if = "Option::is_none")]
820    pub stream: Option<bool>,
821
822    #[serde(skip_serializing_if = "Option::is_none")]
823    pub stream_options: Option<ChatCompletionStreamOptions>,
824
825    /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random,
826    /// while lower values like 0.2 will make it more focused and deterministic.
827    ///
828    /// We generally recommend altering this or `top_p` but not both.
829    #[serde(skip_serializing_if = "Option::is_none")]
830    pub temperature: Option<f32>, // min: 0, max: 2, default: 1,
831
832    /// An alternative to sampling with temperature, called nucleus sampling,
833    /// where the model considers the results of the tokens with top_p probability mass.
834    /// So 0.1 means only the tokens comprising the top 10% probability mass are considered.
835    ///
836    ///  We generally recommend altering this or `temperature` but not both.
837    #[serde(skip_serializing_if = "Option::is_none")]
838    pub top_p: Option<f32>, // min: 0, max: 1, default: 1
839
840    /// A list of tools the model may call. Currently, only functions are supported as a tool.
841    /// Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.
842    #[serde(skip_serializing_if = "Option::is_none")]
843    pub tools: Option<Vec<ChatCompletionTool>>,
844
845    #[serde(skip_serializing_if = "Option::is_none")]
846    pub tool_choice: Option<ChatCompletionToolChoiceOption>,
847
848    /// Whether to enable [parallel function calling](https://platform.openai.com/docs/guides/function-calling/parallel-function-calling) during tool use.
849    #[serde(skip_serializing_if = "Option::is_none")]
850    pub parallel_tool_calls: Option<bool>,
851
852    /// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
853    #[serde(skip_serializing_if = "Option::is_none")]
854    pub user: Option<String>,
855
856    /// This tool searches the web for relevant results to use in a response.
857    /// Learn more about the [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
858    #[serde(skip_serializing_if = "Option::is_none")]
859    pub web_search_options: Option<WebSearchOptions>,
860
861    /// Deprecated in favor of `tool_choice`.
862    ///
863    /// Controls which (if any) function is called by the model.
864    /// `none` means the model will not call a function and instead generates a message.
865    /// `auto` means the model can pick between generating a message or calling a function.
866    /// Specifying a particular function via `{"name": "my_function"}` forces the model to call that function.
867    ///
868    /// `none` is the default when no functions are present. `auto` is the default if functions are present.
869    #[deprecated]
870    #[serde(skip_serializing_if = "Option::is_none")]
871    pub function_call: Option<ChatCompletionFunctionCall>,
872
873    /// Deprecated in favor of `tools`.
874    ///
875    /// A list of functions the model may generate JSON inputs for.
876    #[deprecated]
877    #[serde(skip_serializing_if = "Option::is_none")]
878    pub functions: Option<Vec<ChatCompletionFunctions>>,
879
880    /// The key to use for caching the prompt.
881    #[serde(skip_serializing_if = "Option::is_none")]
882    pub prompt_cache_key: Option<String>,
883}
884
885/// Options for streaming response. Only set this when you set `stream: true`.
886#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
887pub struct ChatCompletionStreamOptions {
888    /// If set, an additional chunk will be streamed before the `data: [DONE]` message. The `usage` field on this chunk shows the token usage statistics for the entire request, and the `choices` field will always be an empty array. All other chunks will also include a `usage` field, but with a null value.
889    pub include_usage: bool,
890}
891
892#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
893#[serde(rename_all = "snake_case")]
894pub enum FinishReason {
895    #[serde(alias = "eos")]
896    Stop,
897    Length,
898    ToolCalls,
899    ContentFilter,
900    FunctionCall,
901}
902
903#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
904pub struct TopLogprobs {
905    /// The token.
906    pub token: String,
907    /// The log probability of this token.
908    pub logprob: f32,
909    /// A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be `null` if there is no bytes representation for the token.
910    pub bytes: Option<Vec<u8>>,
911}
912
913#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
914pub struct ChatCompletionTokenLogprob {
915    /// The token.
916    pub token: String,
917    /// The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value `-9999.0` is used to signify that the token is very unlikely.
918    pub logprob: f32,
919    /// A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be `null` if there is no bytes representation for the token.
920    pub bytes: Option<Vec<u8>>,
921    ///  List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested `top_logprobs` returned.
922    pub top_logprobs: Vec<TopLogprobs>,
923}
924
925#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
926pub struct ChatChoiceLogprobs {
927    /// A list of message content tokens with log probability information.
928    pub content: Option<Vec<ChatCompletionTokenLogprob>>,
929    pub refusal: Option<Vec<ChatCompletionTokenLogprob>>,
930}
931
932#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
933pub struct ChatChoice {
934    /// The index of the choice in the list of choices.
935    pub index: u32,
936    pub message: ChatCompletionResponseMessage,
937    /// The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,
938    /// `length` if the maximum number of tokens specified in the request was reached,
939    /// `content_filter` if content was omitted due to a flag from our content filters,
940    /// `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.
941    pub finish_reason: Option<FinishReason>,
942    /// Log probability information for the choice.
943    pub logprobs: Option<ChatChoiceLogprobs>,
944}
945
946/// Represents a chat completion response returned by model, based on the provided input.
947#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
948pub struct CreateChatCompletionResponse {
949    /// A unique identifier for the chat completion.
950    pub id: String,
951    /// A list of chat completion choices. Can be more than one if `n` is greater than 1.
952    pub choices: Vec<ChatChoice>,
953    /// The Unix timestamp (in seconds) of when the chat completion was created.
954    pub created: u32,
955    /// The model used for the chat completion.
956    pub model: String,
957    /// The service tier used for processing the request. This field is only included if the `service_tier` parameter is specified in the request.
958    pub service_tier: Option<ServiceTierResponse>,
959    /// This fingerprint represents the backend configuration that the model runs with.
960    ///
961    /// Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
962    pub system_fingerprint: Option<String>,
963
964    /// The object type, which is always `chat.completion`.
965    pub object: Option<String>,
966    pub usage: Option<CompletionUsage>,
967}
968
969/// Parsed server side events stream until an \[DONE\] is received from server.
970pub type ChatCompletionResponseStream =
971    Pin<Box<dyn Stream<Item = Result<CreateChatCompletionStreamResponse, OpenAIError>> + Send>>;
972
973#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
974pub struct FunctionCallStream {
975    /// The name of the function to call.
976    pub name: Option<String>,
977    /// The arguments to call the function with, as generated by the model in JSON format.
978    /// Note that the model does not always generate valid JSON, and may hallucinate
979    /// parameters not defined by your function schema. Validate the arguments in your
980    /// code before calling your function.
981    pub arguments: Option<String>,
982}
983
984#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
985pub struct ChatCompletionMessageToolCallChunk {
986    pub index: u32,
987    /// The ID of the tool call.
988    pub id: Option<String>,
989    /// The type of the tool. Currently, only `function` is supported.
990    pub r#type: Option<ChatCompletionToolType>,
991    pub function: Option<FunctionCallStream>,
992}
993
994/// A chat completion delta generated by streamed model responses.
995#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
996pub struct ChatCompletionStreamResponseDelta {
997    /// The contents of the chunk message.
998    pub content: Option<String>,
999    /// Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model.
1000    #[deprecated]
1001    pub function_call: Option<FunctionCallStream>,
1002
1003    pub tool_calls: Option<Vec<ChatCompletionMessageToolCallChunk>>,
1004    /// The role of the author of this message.
1005    pub role: Option<Role>,
1006    /// The refusal message generated by the model.
1007    pub refusal: Option<String>,
1008}
1009
1010#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
1011pub struct ChatChoiceStream {
1012    /// The index of the choice in the list of choices.
1013    pub index: u32,
1014    pub delta: ChatCompletionStreamResponseDelta,
1015    /// The reason the model stopped generating tokens. This will be
1016    /// `stop` if the model hit a natural stop point or a provided
1017    /// stop sequence,
1018    ///
1019    /// `length` if the maximum number of tokens specified in the
1020    /// request was reached,
1021    /// `content_filter` if content was omitted due to a flag from our
1022    /// content filters,
1023    /// `tool_calls` if the model called a tool, or `function_call`
1024    /// (deprecated) if the model called a function.
1025    pub finish_reason: Option<FinishReason>,
1026    /// Log probability information for the choice.
1027    pub logprobs: Option<ChatChoiceLogprobs>,
1028}
1029
1030#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
1031/// Represents a streamed chunk of a chat completion response returned by model, based on the provided input.
1032pub struct CreateChatCompletionStreamResponse {
1033    /// A unique identifier for the chat completion. Each chunk has the same ID.
1034    pub id: String,
1035    /// A list of chat completion choices. Can contain more than one elements if `n` is greater than 1. Can also be empty for the last chunk if you set `stream_options: {"include_usage": true}`.
1036    pub choices: Vec<ChatChoiceStream>,
1037
1038    /// The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp.
1039    pub created: u32,
1040    /// The model to generate the completion.
1041    pub model: String,
1042    /// The service tier used for processing the request. This field is only included if the `service_tier` parameter is specified in the request.
1043    pub service_tier: Option<ServiceTierResponse>,
1044    /// This fingerprint represents the backend configuration that the model runs with.
1045    /// Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
1046    pub system_fingerprint: Option<String>,
1047    /// The object type, which is always `chat.completion.chunk`.
1048    pub object: Option<String>,
1049
1050    /// An optional field that will only be present when you set `stream_options: {"include_usage": true}` in your request.
1051    /// When present, it contains a null value except for the last chunk which contains the token usage statistics for the entire request.
1052    pub usage: Option<CompletionUsage>,
1053}