package openai // ChatMessage represents a single message within a chat completion request or response. type ChatMessage struct { Role string `json:"role"` Content string `json:"content"` } // ChatCompletionRequest encapsulates the payload for the OpenAI Chat Completions API. type ChatCompletionRequest struct { Model string `json:"model"` Messages []ChatMessage `json:"messages"` MaxTokens *int `json:"max_tokens,omitempty"` Temperature *float64 `json:"temperature,omitempty"` Stream bool `json:"stream,omitempty"` } // ChatCompletionChoice captures an individual response choice returned from the API. type ChatCompletionChoice struct { Index int `json:"index"` Message ChatMessage `json:"message"` FinishReason string `json:"finish_reason"` } // Usage captures token accounting for a chat completion call. type Usage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` } // ChatCompletionResponse represents the top-level response payload from the API. type ChatCompletionResponse struct { ID string `json:"id"` Object string `json:"object"` Choices []ChatCompletionChoice `json:"choices"` Usage Usage `json:"usage"` } // ChatCompletionStreamEvent represents a single chunk in a streaming chat completion. type ChatCompletionStreamEvent struct { ID string `json:"-"` Role string `json:"-"` Content string `json:"-"` FinishReason string `json:"-"` Usage *Usage `json:"-"` Done bool `json:"-"` } // ChatCompletionStreamHandler consumes streaming completion events. type ChatCompletionStreamHandler func(ChatCompletionStreamEvent) error // APIError captures structured error responses returned by the API. type APIError struct { Message string `json:"message"` Type string `json:"type"` Param string `json:"param"` Code any `json:"code"` } // ErrorResponse is returned on non-2xx responses. type ErrorResponse struct { Error APIError `json:"error"` }