Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(OpenAI): Add Image Response usage #571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

abikali
Copy link
Contributor

@abikali abikali commented Apr 30, 2025

What:

  • New Feature

Description:

This PR adds support for tracking token usage in image generation, editing, and variation responses that got introduced in gpt-image-1 (https://platform.openai.com/docs/api-reference/images/object).

The changes include:

  1. Added new response classes ImageResponseUsage and ImageResponseUsageInputTokensDetails to handle usage data
  2. Updated existing image response classes (CreateResponse, EditResponse, and VariationResponse) to include usage information
  3. Added comprehensive test coverage for the new usage tracking functionality
  4. Updated type definitions and documentation to reflect the new usage fields

The usage information includes:

  • Total tokens used
  • Input tokens
  • Output tokens
  • Detailed breakdown of input tokens (text tokens and image tokens)

This feature allows developers to track and monitor token consumption when working with OpenAI's image generation endpoints.

Related:

This PR addresses the need to track token usage in image-related operations, similar to how it's already implemented for text-based operations. It helps developers better understand and optimize their usage of OpenAI's image generation capabilities.

fixes: #569 (issue)
closes: #570 (dupe)

@abikali abikali force-pushed the feature/add-image-response-usage branch from f77ed63 to 73e19ae Compare April 30, 2025 01:44
@iBotPeaches iBotPeaches changed the title feat: Add Image response usage feat(OpenAI): Add Image Response usage Apr 30, 2025
@iBotPeaches
Copy link
Collaborator

Confirmed working in some sample runs.

  +usage: OpenAI\Responses\Images\ImageResponseUsage {#581
    +totalTokens: 4172
    +inputTokens: 12
    +outputTokens: 4160
    +inputTokensDetails: OpenAI\Responses\Images\ImageResponseUsageInputTokensDetails {#578
      +textTokens: 12
      +imageTokens: 0
    }
  }

@iBotPeaches iBotPeaches merged commit d7e3238 into openai-php:main Apr 30, 2025
10 checks passed
@iBotPeaches
Copy link
Collaborator

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add usage to Image response
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.