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