Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Cohere ai Cohere python ApiMeta Model

From Leeroopedia
Knowledge Sources
Domains SDK, API Metadata
Last Updated 2026-02-15 14:00 GMT

Overview

The ApiMeta class is a Pydantic model representing metadata returned with Cohere API responses.

Description

The ApiMeta model provides structured access to metadata that accompanies Cohere API responses. It includes the API version information via ApiMetaApiVersion, a breakdown of billed units via ApiMetaBilledUnits, token usage statistics via ApiMetaTokens, a count of cached tokens that hit the inference cache, and any warnings generated during request processing. This model extends UncheckedBaseModel and is auto-generated from the Cohere API definition by Fern.

Usage

Use this model to inspect billing, token usage, API version, and warning information after making any Cohere API call. It is typically accessible as a meta attribute on API response objects.

Code Reference

Source Location

Signature

class ApiMeta(UncheckedBaseModel):
    api_version: typing.Optional[ApiMetaApiVersion] = None
    billed_units: typing.Optional[ApiMetaBilledUnits] = None
    tokens: typing.Optional[ApiMetaTokens] = None
    cached_tokens: typing.Optional[float] = pydantic.Field(default=None)
    warnings: typing.Optional[typing.List[str]] = None

Import

from cohere.types import ApiMeta

I/O Contract

Field Type Required Default Description
api_version Optional[ApiMetaApiVersion] No None The API version information for the response.
billed_units Optional[ApiMetaBilledUnits] No None Breakdown of billed units by category (tokens, images, search units, classifications).
tokens Optional[ApiMetaTokens] No None Token usage statistics for the request.
cached_tokens Optional[float] No None The number of prompt tokens that hit the inference cache.
warnings Optional[List[str]] No None List of warning messages generated during request processing.

Usage Examples

import cohere

client = cohere.Client(api_key="YOUR_API_KEY")

response = client.chat(
    model="command-r-plus",
    message="Explain quantum computing in simple terms.",
)

# Access the ApiMeta object
meta = response.meta

if meta is not None:
    # Check API version
    if meta.api_version is not None:
        print(meta.api_version)

    # Inspect billed units
    if meta.billed_units is not None:
        print(f"Input tokens billed: {meta.billed_units.input_tokens}")
        print(f"Output tokens billed: {meta.billed_units.output_tokens}")

    # Check cached tokens
    if meta.cached_tokens is not None:
        print(f"Cached tokens: {meta.cached_tokens}")

    # Review any warnings
    if meta.warnings:
        for warning in meta.warnings:
            print(f"Warning: {warning}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment