LocalAI/core/http
lif 0d0ef0121c
fix: Usage for image generation is incorrect (and causes error in LiteLLM) (#7786)
* fix: Add usage fields to image generation response for OpenAI API compatibility

Fixes #7354

Added input_tokens, output_tokens, and input_tokens_details fields to the
image generation API response to comply with OpenAI's image generation API
specification. This resolves validation errors in LiteLLM and the OpenAI SDK.

Changes:
- Added InputTokensDetails struct with text_tokens and image_tokens fields
- Extended OpenAIUsage struct with input_tokens, output_tokens, and input_tokens_details
- Updated ImageEndpoint to populate usage object with required fields
- Updated InpaintingEndpoint to populate usage object with required fields
- All fields initialized to 0 as per current behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: majiayu000 <1835304752@qq.com>

* fix: Correct usage field types for image generation API compatibility

Changed InputTokens and OutputTokens from pointer types (*int) to
regular int types to match OpenAI API specification. This fixes
validation errors with LiteLLM and OpenAI SDK when parsing image
generation responses.

Fixes #7354

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: majiayu000 <1835304752@qq.com>

---------

Signed-off-by: majiayu000 <1835304752@qq.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 09:53:05 +01:00
..
endpoints fix: Usage for image generation is incorrect (and causes error in LiteLLM) (#7786) 2025-12-30 09:53:05 +01:00
middleware feat(api): Allow tracing of requests and responses (#7609) 2025-12-29 11:06:06 +01:00
routes feat(api): Allow tracing of requests and responses (#7609) 2025-12-29 11:06:06 +01:00
static fix(chat-ui): model selection toggle and new chat (#7574) 2025-12-14 22:29:11 +01:00
views feat(api): Allow tracing of requests and responses (#7609) 2025-12-29 11:06:06 +01:00
app.go chore(logging): be consistent and do not emit logs from echo (#7710) 2025-12-24 09:22:27 +01:00
app_test.go chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
explorer.go chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
http_suite_test.go fix(llama-cpp): correctly calculate embeddings (#6259) 2025-09-13 23:11:54 +02:00
openai_mapping_test.go feat(api): OpenAI video create enpoint integration (#6777) 2025-10-27 10:06:57 +01:00
openai_videos_test.go feat: migrate to echo and enable cancellation of non-streaming requests (#7270) 2025-11-14 22:57:53 +01:00
render.go feat: migrate to echo and enable cancellation of non-streaming requests (#7270) 2025-11-14 22:57:53 +01:00