@@ -168,20 +168,20 @@ public struct ChatStreamResult: Codable, Equatable, Sendable {
168168 }
169169
170170 /// A unique identifier for the chat completion. Each chunk has the same ID.
171- public let id : String
171+ public let id : String ?
172172
173173 /// The object type, which is always `chat.completion.chunk`.
174- public let object : String
174+ public let object : String ?
175175
176176 /// The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp.
177- public let created : TimeInterval
177+ public let created : TimeInterval ?
178178
179179 /// The model to generate the completion.
180- public let model : String
181-
180+ public let model : String ?
181+
182182 /// A list of chat completion choices. Can contain more than one element if `n` is greater than 1.
183183 /// Can also be empty for the last chunk if you set `stream_options: {"include_usage": true}`.
184- public let choices : [ Choice ]
184+ public let choices : [ Choice ] ?
185185
186186 /// This fingerprint represents the backend configuration that the model runs with.
187187 /// Can be used in conjunction with the `seed` request parameter to understand when backend changes
@@ -228,12 +228,12 @@ public struct ChatStreamResult: Codable, Equatable, Sendable {
228228 let container = try decoder. container ( keyedBy: CodingKeys . self)
229229 let parsingOptions = decoder. userInfo [ . parsingOptions] as? ParsingOptions ?? [ ]
230230
231- self . id = try container. decodeString ( forKey: . id, parsingOptions: parsingOptions)
232- self . object = try container. decodeString ( forKey: . object, parsingOptions: parsingOptions)
233- self . created = try container. decode ( TimeInterval . self, forKey: . created)
234- self . model = try container. decodeString ( forKey: . model, parsingOptions: parsingOptions)
231+ self . id = try container. decodeStringIfPresent ( forKey: . id, parsingOptions: parsingOptions)
232+ self . object = try container. decodeStringIfPresent ( forKey: . object, parsingOptions: parsingOptions)
233+ self . created = try container. decodeIfPresent ( TimeInterval . self, forKey: . created)
234+ self . model = try container. decodeStringIfPresent ( forKey: . model, parsingOptions: parsingOptions)
235235 self . citations = try container. decodeIfPresent ( [ String ] . self, forKey: . citations)
236- self . choices = try container. decode ( [ ChatStreamResult . Choice ] . self, forKey: . choices)
236+ self . choices = try container. decodeIfPresent ( [ ChatStreamResult . Choice ] . self, forKey: . choices)
237237 self . systemFingerprint = try container. decodeIfPresent ( String . self, forKey: . systemFingerprint)
238238
239239 // Even though API Reference declares that usage field should be either informative or null: https://platform.openai.com/docs/api-reference/chat/create#chat-create-stream_options
0 commit comments