Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Packages/LocalChatNetworking/Sources/OpenAIWire.swift3// Description: OpenAI-compatible wire types (chat completions, streaming chunks, models, embeddings, errors) with lenient decoding.4import Foundation5import LocalChatCore67public enum OpenAI {8 // MARK: Messages910 public struct ImageURL: Codable, Sendable, Hashable {11 public var url: String12 public var detail: String?13 public init(url: String, detail: String? = nil) { self.url = url; self.detail = detail }14 public init(from decoder: Decoder) throws {15 // some clients send the URL as a bare string instead of {"url": …}16 if let s = try? decoder.singleValueContainer().decode(String.self) { url = s; detail = nil; return }17 let c = try decoder.container(keyedBy: CodingKeys.self)18 url = try c.decode(String.self, forKey: .url); detail = try? c.decodeIfPresent(String.self, forKey: .detail)19 }20 enum CodingKeys: String, CodingKey { case url, detail }21 }2223 public struct ContentPart: Codable, Sendable, Hashable {24 public var type: String25 public var text: String?26 public var imageURL: ImageURL?27 public init(text: String) { type = "text"; self.text = text }28 public init(imageURL: String) { type = "image_url"; self.imageURL = ImageURL(url: imageURL) }29 enum CodingKeys: String, CodingKey { case type, text; case imageURL = "image_url" }30 public init(from decoder: Decoder) throws {31 let c = try decoder.container(keyedBy: CodingKeys.self)32 type = (try? c.decode(String.self, forKey: .type)) ?? "text"33 text = try? c.decodeIfPresent(String.self, forKey: .text)34 imageURL = try? c.decodeIfPresent(ImageURL.self, forKey: .imageURL)35 }36 }3738 public enum Content: Codable, Sendable, Hashable {39 case text(String)40 case parts([ContentPart])41 public init(from decoder: Decoder) throws {42 let c = try decoder.singleValueContainer()43 if let s = try? c.decode(String.self) { self = .text(s) } else { self = .parts(try c.decode([ContentPart].self)) }44 }45 public func encode(to encoder: Encoder) throws {46 var c = encoder.singleValueContainer()47 switch self { case .text(let s): try c.encode(s); case .parts(let p): try c.encode(p) }48 }49 public var plainText: String {50 switch self {51 case .text(let s): s52 case .parts(let parts): parts.compactMap { $0.type == "text" || $0.type == "input_text" ? $0.text : nil }.joined(separator: "\n")53 }54 }55 }5657 public struct FunctionCall: Codable, Sendable, Hashable {58 public var name: String?59 public var arguments: String? // JSON text; streamed in fragments60 public init(name: String? = nil, arguments: String? = nil) { self.name = name; self.arguments = arguments }61 public init(from decoder: Decoder) throws {62 let c = try decoder.container(keyedBy: CodingKeys.self)63 name = try? c.decodeIfPresent(String.self, forKey: .name)64 if let s = try? c.decodeIfPresent(String.self, forKey: .arguments) { arguments = s }65 else if let v = try? c.decodeIfPresent(JSONValue.self, forKey: .arguments), v != .null { arguments = v.serialized() } // some servers send an object66 else { arguments = nil }67 }68 enum CodingKeys: String, CodingKey { case name, arguments }69 }7071 public struct ToolCall: Codable, Sendable, Hashable {72 public var index: Int?73 public var id: String?74 public var type: String?75 public var function: FunctionCall?76 public init(index: Int? = nil, id: String? = nil, type: String? = "function", function: FunctionCall? = nil) {77 self.index = index; self.id = id; self.type = type; self.function = function78 }79 }8081 public struct Message: Codable, Sendable, Hashable {82 public var role: String83 public var content: Content?84 public var reasoningContent: String?85 public var toolCalls: [ToolCall]?86 public var toolCallID: String?87 public var name: String?88 public init(role: String, content: Content? = nil, reasoningContent: String? = nil, toolCalls: [ToolCall]? = nil, toolCallID: String? = nil, name: String? = nil) {89 self.role = role; self.content = content; self.reasoningContent = reasoningContent; self.toolCalls = toolCalls; self.toolCallID = toolCallID; self.name = name90 }91 enum CodingKeys: String, CodingKey { case role, content, name; case reasoningContent = "reasoning_content"; case toolCalls = "tool_calls"; case toolCallID = "tool_call_id" }92 public init(from decoder: Decoder) throws {93 let c = try decoder.container(keyedBy: CodingKeys.self)94 role = try c.decode(String.self, forKey: .role)95 content = try? c.decodeIfPresent(Content.self, forKey: .content)96 reasoningContent = try? c.decodeIfPresent(String.self, forKey: .reasoningContent)97 toolCalls = try? c.decodeIfPresent([ToolCall].self, forKey: .toolCalls)98 toolCallID = try? c.decodeIfPresent(String.self, forKey: .toolCallID)99 name = try? c.decodeIfPresent(String.self, forKey: .name)100 }101 }102103 // MARK: Chat completion request104105 public struct FunctionDefinition: Codable, Sendable, Hashable {106 public var name: String107 public var description: String?108 public var parameters: JSONValue?109 public init(name: String, description: String? = nil, parameters: JSONValue? = nil) { self.name = name; self.description = description; self.parameters = parameters }110 }111112 public struct Tool: Codable, Sendable, Hashable {113 public var type: String114 public var function: FunctionDefinition115 public init(function: FunctionDefinition) { type = "function"; self.function = function }116 public init(from decoder: Decoder) throws {117 let c = try decoder.container(keyedBy: CodingKeys.self)118 type = (try? c.decode(String.self, forKey: .type)) ?? "function"119 function = try c.decode(FunctionDefinition.self, forKey: .function)120 }121 enum CodingKeys: String, CodingKey { case type, function }122 }123124 public struct StreamOptions: Codable, Sendable, Hashable {125 public var includeUsage: Bool?126 public init(includeUsage: Bool? = true) { self.includeUsage = includeUsage }127 enum CodingKeys: String, CodingKey { case includeUsage = "include_usage" }128 }129130 public struct JSONSchemaFormat: Codable, Sendable, Hashable {131 public var name: String?132 public var schema: JSONValue?133 public var strict: Bool?134 public init(name: String? = "response", schema: JSONValue?, strict: Bool? = true) { self.name = name; self.schema = schema; self.strict = strict }135 }136137 public struct ResponseFormat: Codable, Sendable, Hashable {138 public var type: String // "text", "json_object", "json_schema"139 public var jsonSchema: JSONSchemaFormat?140 public init(type: String, jsonSchema: JSONSchemaFormat? = nil) { self.type = type; self.jsonSchema = jsonSchema }141 enum CodingKeys: String, CodingKey { case type; case jsonSchema = "json_schema" }142 }143144 /// `stop` is a string or an array of strings.145 public struct StopList: Codable, Sendable, Hashable {146 public var values: [String]147 public init(_ values: [String]) { self.values = values }148 public init(from decoder: Decoder) throws {149 let c = try decoder.singleValueContainer()150 if let s = try? c.decode(String.self) { values = [s] } else { values = (try? c.decode([String].self)) ?? [] }151 }152 public func encode(to encoder: Encoder) throws { var c = encoder.singleValueContainer(); try c.encode(values) }153 }154155 public struct ChatRequest: Codable, Sendable {156 public var model: String157 public var messages: [Message]158 public var tools: [Tool]?159 public var toolChoice: JSONValue?160 public var temperature: Double?161 public var topP: Double?162 public var topK: Int? // extension accepted by llama.cpp, LM Studio, Local Chat163 public var minP: Double?164 public var repetitionPenalty: Double?165 public var maxTokens: Int?166 public var maxCompletionTokens: Int?167 public var stop: StopList?168 public var seed: UInt64?169 public var stream: Bool?170 public var streamOptions: StreamOptions?171 public var responseFormat: ResponseFormat?172 public var reasoningEffort: String? // "none"/"minimal" disables thinking173 public var enableThinking: Bool? // extension174175 public init(model: String, messages: [Message]) { self.model = model; self.messages = messages }176177 enum CodingKeys: String, CodingKey {178 case model, messages, tools, temperature, stop, seed, stream179 case toolChoice = "tool_choice", topP = "top_p", topK = "top_k", minP = "min_p", repetitionPenalty = "repetition_penalty"180 case maxTokens = "max_tokens", maxCompletionTokens = "max_completion_tokens", streamOptions = "stream_options"181 case responseFormat = "response_format", reasoningEffort = "reasoning_effort", enableThinking = "enable_thinking"182 }183 public init(from decoder: Decoder) throws {184 let c = try decoder.container(keyedBy: CodingKeys.self)185 model = try c.decode(String.self, forKey: .model)186 messages = try c.decode([Message].self, forKey: .messages)187 tools = try? c.decodeIfPresent([Tool].self, forKey: .tools)188 toolChoice = try? c.decodeIfPresent(JSONValue.self, forKey: .toolChoice)189 temperature = try? c.decodeIfPresent(Double.self, forKey: .temperature)190 topP = try? c.decodeIfPresent(Double.self, forKey: .topP)191 topK = try? c.decodeIfPresent(Int.self, forKey: .topK)192 minP = try? c.decodeIfPresent(Double.self, forKey: .minP)193 repetitionPenalty = try? c.decodeIfPresent(Double.self, forKey: .repetitionPenalty)194 maxTokens = try? c.decodeIfPresent(Int.self, forKey: .maxTokens)195 maxCompletionTokens = try? c.decodeIfPresent(Int.self, forKey: .maxCompletionTokens)196 stop = try? c.decodeIfPresent(StopList.self, forKey: .stop)197 if let s = try? c.decodeIfPresent(UInt64.self, forKey: .seed) { seed = s }198 else if let s = try? c.decodeIfPresent(Int64.self, forKey: .seed) { seed = UInt64(bitPattern: s) } else { seed = nil }199 stream = try? c.decodeIfPresent(Bool.self, forKey: .stream)200 streamOptions = try? c.decodeIfPresent(StreamOptions.self, forKey: .streamOptions)201 responseFormat = try? c.decodeIfPresent(ResponseFormat.self, forKey: .responseFormat)202 reasoningEffort = try? c.decodeIfPresent(String.self, forKey: .reasoningEffort)203 enableThinking = try? c.decodeIfPresent(Bool.self, forKey: .enableThinking)204 }205 }206207 // MARK: Chat completion response208209 public struct PromptTokensDetails: Codable, Sendable, Hashable {210 public var cachedTokens: Int?211 public init(cachedTokens: Int?) { self.cachedTokens = cachedTokens }212 enum CodingKeys: String, CodingKey { case cachedTokens = "cached_tokens" }213 }214 public struct CompletionTokensDetails: Codable, Sendable, Hashable {215 public var reasoningTokens: Int?216 public init(reasoningTokens: Int?) { self.reasoningTokens = reasoningTokens }217 enum CodingKeys: String, CodingKey { case reasoningTokens = "reasoning_tokens" }218 }219220 public struct Usage: Codable, Sendable, Hashable {221 public var promptTokens: Int?222 public var completionTokens: Int?223 public var totalTokens: Int?224 public var promptTokensDetails: PromptTokensDetails?225 public var completionTokensDetails: CompletionTokensDetails?226 public init(promptTokens: Int?, completionTokens: Int?, cachedTokens: Int? = nil, reasoningTokens: Int? = nil) {227 self.promptTokens = promptTokens; self.completionTokens = completionTokens228 if let p = promptTokens, let c = completionTokens { totalTokens = p + c }229 if let cachedTokens { promptTokensDetails = PromptTokensDetails(cachedTokens: cachedTokens) }230 if let reasoningTokens { completionTokensDetails = CompletionTokensDetails(reasoningTokens: reasoningTokens) }231 }232 enum CodingKeys: String, CodingKey {233 case promptTokens = "prompt_tokens", completionTokens = "completion_tokens", totalTokens = "total_tokens"234 case promptTokensDetails = "prompt_tokens_details", completionTokensDetails = "completion_tokens_details"235 }236 public init(from decoder: Decoder) throws {237 let c = try decoder.container(keyedBy: CodingKeys.self)238 promptTokens = try? c.decodeIfPresent(Int.self, forKey: .promptTokens)239 completionTokens = try? c.decodeIfPresent(Int.self, forKey: .completionTokens)240 totalTokens = try? c.decodeIfPresent(Int.self, forKey: .totalTokens)241 promptTokensDetails = try? c.decodeIfPresent(PromptTokensDetails.self, forKey: .promptTokensDetails)242 completionTokensDetails = try? c.decodeIfPresent(CompletionTokensDetails.self, forKey: .completionTokensDetails)243 }244 }245246 /// Local Chat extension: timings and memory measured by the serving node (ignored by other clients).247 public struct ServerMetrics: Codable, Sendable, Hashable {248 public var timeToFirstToken: Double?249 public var promptTime: Double?250 public var generationTime: Double?251 public var totalTime: Double?252 public var peakMemoryBytes: Int64?253 public var activeMemoryBytes: Int64?254 public init(_ m: GenerationMetrics) {255 timeToFirstToken = m.timeToFirstToken; promptTime = m.promptTime; generationTime = m.generationTime; totalTime = m.totalTime256 peakMemoryBytes = m.peakMemoryBytes; activeMemoryBytes = m.activeMemoryBytes257 }258 enum CodingKeys: String, CodingKey {259 case timeToFirstToken = "time_to_first_token", promptTime = "prompt_time", generationTime = "generation_time", totalTime = "total_time"260 case peakMemoryBytes = "peak_memory_bytes", activeMemoryBytes = "active_memory_bytes"261 }262 }263264 public struct Choice: Codable, Sendable {265 public var index: Int266 public var message: Message267 public var finishReason: String?268 public init(index: Int = 0, message: Message, finishReason: String?) { self.index = index; self.message = message; self.finishReason = finishReason }269 enum CodingKeys: String, CodingKey { case index, message; case finishReason = "finish_reason" }270 }271272 public struct ChatResponse: Codable, Sendable {273 public var id: String274 public var object: String275 public var created: Int276 public var model: String277 public var choices: [Choice]278 public var usage: Usage?279 public var localChat: ServerMetrics?280 public init(id: String, created: Int, model: String, choices: [Choice], usage: Usage?, localChat: ServerMetrics? = nil) {281 self.id = id; object = "chat.completion"; self.created = created; self.model = model; self.choices = choices; self.usage = usage; self.localChat = localChat282 }283 enum CodingKeys: String, CodingKey { case id, object, created, model, choices, usage; case localChat = "local_chat" }284 public init(from decoder: Decoder) throws {285 let c = try decoder.container(keyedBy: CodingKeys.self)286 id = (try? c.decode(String.self, forKey: .id)) ?? ""287 object = (try? c.decode(String.self, forKey: .object)) ?? "chat.completion"288 created = (try? c.decode(Int.self, forKey: .created)) ?? 0289 model = (try? c.decode(String.self, forKey: .model)) ?? ""290 choices = (try? c.decode([Choice].self, forKey: .choices)) ?? []291 usage = try? c.decodeIfPresent(Usage.self, forKey: .usage)292 localChat = try? c.decodeIfPresent(ServerMetrics.self, forKey: .localChat)293 }294 }295296 public struct Delta: Codable, Sendable, Hashable {297 public var role: String?298 public var content: String?299 public var reasoningContent: String?300 public var toolCalls: [ToolCall]?301 public init(role: String? = nil, content: String? = nil, reasoningContent: String? = nil, toolCalls: [ToolCall]? = nil) {302 self.role = role; self.content = content; self.reasoningContent = reasoningContent; self.toolCalls = toolCalls303 }304 enum CodingKeys: String, CodingKey { case role, content, reasoning; case reasoningContent = "reasoning_content"; case toolCalls = "tool_calls" }305 public init(from decoder: Decoder) throws {306 let c = try decoder.container(keyedBy: CodingKeys.self)307 role = try? c.decodeIfPresent(String.self, forKey: .role)308 content = try? c.decodeIfPresent(String.self, forKey: .content)309 // "reasoning_content" (DeepSeek, llama.cpp, Local Chat) or "reasoning" (OpenRouter, Ollama)310 reasoningContent = (try? c.decodeIfPresent(String.self, forKey: .reasoningContent)) ?? (try? c.decodeIfPresent(String.self, forKey: .reasoning))311 toolCalls = try? c.decodeIfPresent([ToolCall].self, forKey: .toolCalls)312 }313 public func encode(to encoder: Encoder) throws {314 var c = encoder.container(keyedBy: CodingKeys.self)315 try c.encodeIfPresent(role, forKey: .role); try c.encodeIfPresent(content, forKey: .content)316 try c.encodeIfPresent(reasoningContent, forKey: .reasoningContent); try c.encodeIfPresent(toolCalls, forKey: .toolCalls)317 }318 }319320 public struct ChunkChoice: Codable, Sendable {321 public var index: Int322 public var delta: Delta323 public var finishReason: String?324 public init(index: Int = 0, delta: Delta, finishReason: String? = nil) { self.index = index; self.delta = delta; self.finishReason = finishReason }325 enum CodingKeys: String, CodingKey { case index, delta; case finishReason = "finish_reason" }326 public init(from decoder: Decoder) throws {327 let c = try decoder.container(keyedBy: CodingKeys.self)328 index = (try? c.decode(Int.self, forKey: .index)) ?? 0329 delta = (try? c.decode(Delta.self, forKey: .delta)) ?? Delta()330 finishReason = try? c.decodeIfPresent(String.self, forKey: .finishReason)331 }332 public func encode(to encoder: Encoder) throws {333 var c = encoder.container(keyedBy: CodingKeys.self)334 try c.encode(index, forKey: .index); try c.encode(delta, forKey: .delta)335 if let finishReason { try c.encode(finishReason, forKey: .finishReason) } else { try c.encodeNil(forKey: .finishReason) }336 }337 }338339 public struct ChatChunk: Codable, Sendable {340 public var id: String341 public var object: String342 public var created: Int343 public var model: String344 public var choices: [ChunkChoice]345 public var usage: Usage?346 public var localChat: ServerMetrics?347 public var error: ErrorBody? // some servers report mid-stream failures inside a data event348 public init(id: String, created: Int, model: String, choices: [ChunkChoice], usage: Usage? = nil, localChat: ServerMetrics? = nil) {349 self.id = id; object = "chat.completion.chunk"; self.created = created; self.model = model; self.choices = choices350 self.usage = usage; self.localChat = localChat351 }352 enum CodingKeys: String, CodingKey { case id, object, created, model, choices, usage, error; case localChat = "local_chat" }353 public init(from decoder: Decoder) throws {354 let c = try decoder.container(keyedBy: CodingKeys.self)355 id = (try? c.decode(String.self, forKey: .id)) ?? ""356 object = (try? c.decode(String.self, forKey: .object)) ?? "chat.completion.chunk"357 created = (try? c.decode(Int.self, forKey: .created)) ?? 0358 model = (try? c.decode(String.self, forKey: .model)) ?? ""359 choices = (try? c.decode([ChunkChoice].self, forKey: .choices)) ?? []360 usage = try? c.decodeIfPresent(Usage.self, forKey: .usage)361 localChat = try? c.decodeIfPresent(ServerMetrics.self, forKey: .localChat)362 error = try? c.decodeIfPresent(ErrorBody.self, forKey: .error)363 }364 }365366 // MARK: Models367368 /// Local Chat extension on a model entry, so another Local Chat can show what the remote model is.369 public struct ModelDetails: Codable, Sendable, Hashable {370 public var name: String?371 public var backend: String?372 public var quantization: String?373 public var architecture: String?374 public var contextLength: Int?375 public var parameterCount: Int64?376 public var sizeBytes: Int64?377 public var capabilities: [String]?378 public var loaded: Bool?379 public init(_ d: ModelDescriptor, loaded: Bool? = nil) {380 name = d.name; backend = d.backend.rawValue; quantization = d.quantization; architecture = d.architecture; contextLength = d.contextLength381 parameterCount = d.parameterCount; sizeBytes = d.sizeBytes; capabilities = d.capabilities.map(\.rawValue).sorted(); self.loaded = loaded382 }383 enum CodingKeys: String, CodingKey {384 case name, backend, quantization, architecture, capabilities, loaded385 case contextLength = "context_length", parameterCount = "parameter_count", sizeBytes = "size_bytes"386 }387 }388389 public struct Model: Codable, Sendable, Hashable {390 public var id: String391 public var object: String392 public var created: Int?393 public var ownedBy: String?394 public var localChat: ModelDetails?395 public init(id: String, created: Int? = nil, ownedBy: String? = "local-chat", localChat: ModelDetails? = nil) {396 self.id = id; object = "model"; self.created = created; self.ownedBy = ownedBy; self.localChat = localChat397 }398 enum CodingKeys: String, CodingKey { case id, object, created; case ownedBy = "owned_by"; case localChat = "local_chat" }399 public init(from decoder: Decoder) throws {400 let c = try decoder.container(keyedBy: CodingKeys.self)401 id = try c.decode(String.self, forKey: .id)402 object = (try? c.decode(String.self, forKey: .object)) ?? "model"403 created = try? c.decodeIfPresent(Int.self, forKey: .created)404 ownedBy = try? c.decodeIfPresent(String.self, forKey: .ownedBy)405 localChat = try? c.decodeIfPresent(ModelDetails.self, forKey: .localChat)406 }407 }408409 public struct ModelList: Codable, Sendable {410 public var object: String411 public var data: [Model]412 public init(data: [Model]) { object = "list"; self.data = data }413 public init(from decoder: Decoder) throws {414 let c = try decoder.container(keyedBy: CodingKeys.self)415 object = (try? c.decode(String.self, forKey: .object)) ?? "list"416 data = try c.decode([Model].self, forKey: .data)417 }418 enum CodingKeys: String, CodingKey { case object, data }419 }420421 // MARK: Embeddings422423 public struct EmbeddingInput: Codable, Sendable, Hashable {424 public var values: [String]425 public init(_ values: [String]) { self.values = values }426 public init(from decoder: Decoder) throws {427 let c = try decoder.singleValueContainer()428 if let s = try? c.decode(String.self) { values = [s] } else { values = try c.decode([String].self) }429 }430 public func encode(to encoder: Encoder) throws { var c = encoder.singleValueContainer(); try c.encode(values) }431 }432433 public struct EmbeddingRequest: Codable, Sendable {434 public var model: String435 public var input: EmbeddingInput436 public var encodingFormat: String?437 public init(model: String, input: [String]) { self.model = model; self.input = EmbeddingInput(input) }438 enum CodingKeys: String, CodingKey { case model, input; case encodingFormat = "encoding_format" }439 }440441 public struct Embedding: Codable, Sendable {442 public var object: String443 public var index: Int444 public var embedding: [Float]445 public init(index: Int, embedding: [Float]) { object = "embedding"; self.index = index; self.embedding = embedding }446 public init(from decoder: Decoder) throws {447 let c = try decoder.container(keyedBy: CodingKeys.self)448 object = (try? c.decode(String.self, forKey: .object)) ?? "embedding"449 index = (try? c.decode(Int.self, forKey: .index)) ?? 0450 embedding = try c.decode([Float].self, forKey: .embedding)451 }452 enum CodingKeys: String, CodingKey { case object, index, embedding }453 }454455 public struct EmbeddingResponse: Codable, Sendable {456 public var object: String457 public var data: [Embedding]458 public var model: String459 public var usage: Usage?460 public init(data: [Embedding], model: String, usage: Usage?) { object = "list"; self.data = data; self.model = model; self.usage = usage }461 public init(from decoder: Decoder) throws {462 let c = try decoder.container(keyedBy: CodingKeys.self)463 object = (try? c.decode(String.self, forKey: .object)) ?? "list"464 data = try c.decode([Embedding].self, forKey: .data)465 model = (try? c.decode(String.self, forKey: .model)) ?? ""466 usage = try? c.decodeIfPresent(Usage.self, forKey: .usage)467 }468 enum CodingKeys: String, CodingKey { case object, data, model, usage }469 }470471 // MARK: Errors472473 public struct ErrorBody: Codable, Sendable, Hashable {474 public var message: String475 public var type: String?476 public var code: String?477 public init(message: String, type: String? = nil, code: String? = nil) { self.message = message; self.type = type; self.code = code }478 public init(from decoder: Decoder) throws {479 if let s = try? decoder.singleValueContainer().decode(String.self) { message = s; type = nil; code = nil; return }480 let c = try decoder.container(keyedBy: CodingKeys.self)481 message = (try? c.decode(String.self, forKey: .message)) ?? "Unknown error"482 type = try? c.decodeIfPresent(String.self, forKey: .type)483 if let s = try? c.decodeIfPresent(String.self, forKey: .code) { code = s }484 else if let n = try? c.decodeIfPresent(Int.self, forKey: .code) { code = String(n) } else { code = nil }485 }486 enum CodingKeys: String, CodingKey { case message, type, code }487 }488489 public struct ErrorEnvelope: Codable, Sendable, Hashable {490 public var error: ErrorBody491 public init(_ message: String, type: String? = "invalid_request_error", code: String? = nil) { error = ErrorBody(message: message, type: type, code: code) }492 }493}494