Implementation:Cohere ai Cohere python ApiMetaBilledUnits Model
| Knowledge Sources | |
|---|---|
| Domains | SDK, Billing |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
The ApiMetaBilledUnits class is a Pydantic model representing the breakdown of billed units in a Cohere API response.
Description
The ApiMetaBilledUnits model provides a detailed breakdown of all units billed for a given API request. It tracks six categories of billable usage: images, input tokens, image tokens, output tokens, search units, and classifications. All fields are optional floats since not every API call incurs charges across all categories. This model extends UncheckedBaseModel and is auto-generated from the Cohere API definition by Fern. It is typically nested within the ApiMeta model as the billed_units field.
Usage
Use this model to monitor and audit billing consumption after API calls. It is particularly useful for cost tracking, usage analytics, and budget management when integrating Cohere services into production applications.
Code Reference
Source Location
- Repository: Cohere Python SDK
- File:
src/cohere/types/api_meta_billed_units.py
Signature
class ApiMetaBilledUnits(UncheckedBaseModel):
images: typing.Optional[float] = pydantic.Field(default=None)
input_tokens: typing.Optional[float] = pydantic.Field(default=None)
image_tokens: typing.Optional[float] = pydantic.Field(default=None)
output_tokens: typing.Optional[float] = pydantic.Field(default=None)
search_units: typing.Optional[float] = pydantic.Field(default=None)
classifications: typing.Optional[float] = pydantic.Field(default=None)
Import
from cohere.types import ApiMetaBilledUnits
I/O Contract
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
images |
Optional[float] |
No | None |
The number of billed images. |
input_tokens |
Optional[float] |
No | None |
The number of billed input tokens. |
image_tokens |
Optional[float] |
No | None |
The number of billed image tokens. |
output_tokens |
Optional[float] |
No | None |
The number of billed output tokens. |
search_units |
Optional[float] |
No | None |
The number of billed search units. |
classifications |
Optional[float] |
No | None |
The number of billed classification units. |
Usage Examples
import cohere
client = cohere.Client(api_key="YOUR_API_KEY")
response = client.chat(
model="command-r-plus",
message="What is the capital of France?",
)
# Access billed units from the response metadata
billed = response.meta.billed_units
if billed is not None:
print(f"Input tokens billed: {billed.input_tokens}")
print(f"Output tokens billed: {billed.output_tokens}")
print(f"Search units billed: {billed.search_units}")
print(f"Images billed: {billed.images}")
print(f"Image tokens billed: {billed.image_tokens}")
print(f"Classifications billed: {billed.classifications}")
# Calculate total token cost
total_tokens = (billed.input_tokens or 0) + (billed.output_tokens or 0)
print(f"Total tokens: {total_tokens}")