ai.types
Reference for lower-level public type helper modules.
Most message, event, and tool APIs are documented under the root aliases
ai.messages, ai.events, and ai.tools. Use ai.types for lower-level
helper modules that do not have a shorter public alias.
ai.types.media
ai.types.media contains URL, data URL, media type inference, and magic-byte
detection helpers.
URL helpers:
is_urlis_downloadable_urlsplit_data_url
Encoding helpers:
data_to_base64data_to_data_url
Media type helpers:
infer_media_typedetect_media_typedetect_image_media_typedetect_audio_media_type
ai.types.usage
Usage is normalized token usage from a single model call.
usage.input_tokens
usage.output_tokens
usage.reasoning_tokens
usage.cache_read_tokens
usage.cache_write_tokens
usage.raw
usage.total_tokensUse usage_a + usage_b to accumulate usage across calls.