Skip to content

fix(types): include prompt text and image token counts#1902

Open
FU-max-boop wants to merge 1 commit into
openai:masterfrom
FU-max-boop:fix/usage-token-details
Open

fix(types): include prompt text and image token counts#1902
FU-max-boop wants to merge 1 commit into
openai:masterfrom
FU-max-boop:fix/usage-token-details

Conversation

@FU-max-boop
Copy link
Copy Markdown

Summary

Fixes #1718.

CompletionUsage.PromptTokensDetails already exposes audio_tokens and cached_tokens, but chat completions usage payloads for audio/image-capable models can also include text_tokens and image_tokens. This adds those optional fields to the shared completion usage type so response.usage.prompt_tokens_details.text_tokens and .image_tokens type-check for chat completions.

I also added a small type regression test that exercises the shared OpenAI.CompletionUsage surface.

Tests

  • npx -y [email protected] install --frozen-lockfile --ignore-scripts
  • npx -y [email protected] test tests/usage-types.test.ts
  • npx -y [email protected] build
  • ./node_modules/.bin/prettier --check src/resources/completions.ts tests/usage-types.test.ts
  • ./node_modules/.bin/eslint src/resources/completions.ts tests/usage-types.test.ts
  • git diff --check

Note: the full npx -y [email protected] lint run completed prettier/eslint/build, then stopped in its repo-wide type-check step because this checkout does not have optional example dependencies (@azure/identity, express, next) installed. The changed files passed targeted prettier/eslint, and the package build plus type regression test passed.

Git HTTPS push repeatedly timed out to github.com:443 from this environment, so I created the fork branch via the GitHub Git Data API after local validation.

@FU-max-boop FU-max-boop requested a review from a team as a code owner May 28, 2026 22:25
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.

text_tokens and image_tokens not documented or typed

1 participant