Skip to content

Conversation

@yurekami
Copy link

Summary

  • Added image_tokens field to the ApiMetaBilledUnits model
  • Updated merge_meta_field utility to properly merge image_tokens across responses
  • Added tests for the new field

Problem

The embedding API returns an image_tokens field in the billed_units response, but the ApiMetaBilledUnits model only defined an images field. This mismatch caused image_tokens to only be accessible through Pydantic's extra attributes, leading to confusion and type-checking issues.

Example from the issue:

print(resp.meta.billed_units.model_dump_json(indent=2))
# {
#   "images": null,
#   "input_tokens": 0.0,
#   "image_tokens": 2716  # <-- This field was not in the model
# }

Solution

Added the image_tokens field to ApiMetaBilledUnits:

image_tokens: typing.Optional[float] = pydantic.Field(default=None)
"""
The number of billed image tokens.
"""

Also updated merge_meta_field in utils.py to properly sum image_tokens when merging embed responses.

Test plan

  • Added test_image_tokens_field - verifies field can be set, accessed, and serialized
  • Added test_merge_with_image_tokens - verifies image_tokens are properly merged
  • All existing tests continue to pass

Note

The file notes it's "auto-generated by Fern from our API Definition". The API definition may also need to be updated to include this field for future regeneration.

Fixes #711

🤖 Generated with Claude Code

The embedding API returns an `image_tokens` field in the billed_units
response that was not present in the model definition. This caused
the field to only be accessible through extra attributes.

Changes:
- Added `image_tokens` field to `ApiMetaBilledUnits` model
- Updated `merge_meta_field` utility to properly merge image_tokens
- Added tests for image_tokens field and merging

Fixes cohere-ai#711

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

image_tokens missing from embedding response model

1 participant