diff --git a/core/http/endpoints/openai/image.go b/core/http/endpoints/openai/image.go index 745b3c5cb..025abaa94 100644 --- a/core/http/endpoints/openai/image.go +++ b/core/http/endpoints/openai/image.go @@ -232,6 +232,17 @@ func ImageEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfi ID: id, Created: created, Data: result, + Usage: schema.OpenAIUsage{ + PromptTokens: 0, + CompletionTokens: 0, + TotalTokens: 0, + InputTokens: 0, + OutputTokens: 0, + InputTokensDetails: &schema.InputTokensDetails{ + TextTokens: 0, + ImageTokens: 0, + }, + }, } jsonResult, _ := json.Marshal(resp) diff --git a/core/http/endpoints/openai/inpainting.go b/core/http/endpoints/openai/inpainting.go index 205ecad7d..90c5a05d1 100644 --- a/core/http/endpoints/openai/inpainting.go +++ b/core/http/endpoints/openai/inpainting.go @@ -258,6 +258,17 @@ func InpaintingEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, app Data: []schema.Item{{ URL: imgPath, }}, + Usage: schema.OpenAIUsage{ + PromptTokens: 0, + CompletionTokens: 0, + TotalTokens: 0, + InputTokens: 0, + OutputTokens: 0, + InputTokensDetails: &schema.InputTokensDetails{ + TextTokens: 0, + ImageTokens: 0, + }, + }, } // mark success so defer cleanup will not remove output files diff --git a/core/schema/openai.go b/core/schema/openai.go index 604968f5e..be45ca098 100644 --- a/core/schema/openai.go +++ b/core/schema/openai.go @@ -18,10 +18,19 @@ type ErrorResponse struct { Error *APIError `json:"error,omitempty"` } +type InputTokensDetails struct { + TextTokens int `json:"text_tokens"` + ImageTokens int `json:"image_tokens"` +} + type OpenAIUsage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` + // Fields for image generation API compatibility + InputTokens int `json:"input_tokens,omitempty"` + OutputTokens int `json:"output_tokens,omitempty"` + InputTokensDetails *InputTokensDetails `json:"input_tokens_details,omitempty"` // Extra timing data, disabled by default as is't not a part of OpenAI specification TimingPromptProcessing float64 `json:"timing_prompt_processing,omitempty"` TimingTokenGeneration float64 `json:"timing_token_generation,omitempty"` @@ -49,11 +58,11 @@ type OpenAIResponse struct { } type Choice struct { - Index int `json:"index"` - FinishReason *string `json:"finish_reason"` - Message *Message `json:"message,omitempty"` - Delta *Message `json:"delta,omitempty"` - Text string `json:"text,omitempty"` + Index int `json:"index"` + FinishReason *string `json:"finish_reason"` + Message *Message `json:"message,omitempty"` + Delta *Message `json:"delta,omitempty"` + Text string `json:"text,omitempty"` Logprobs *Logprobs `json:"logprobs,omitempty"` }