async_openai_wasm/types/
chat.rs

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