Skip to content

Expose token usage information in API responses #42

@davidperezgar

Description

@davidperezgar

Currently, the wp-ai-client library does not provide a way to retrieve token usage information (e.g. prompt tokens, completion tokens, total tokens) from API responses.

Having access to token usage is important for:

  • Monitoring and controlling costs
  • Debugging and optimizing prompts
  • Displaying usage metrics in WordPress dashboards or logs

Request

Please consider exposing token usage data returned by the underlying AI provider (when available) as part of the response object, or through an optional accessor/helper method.

For example:

  • usage.prompt_tokens
  • usage.completion_tokens
  • usage.total_tokens

Expected behavior

  • Token usage should be returned in a consistent, documented structure.
  • If a provider does not support token usage, the field should be null or omitted gracefully.
  • This change should be backward-compatible with existing implementations.

Additional context

Many AI SDKs (e.g. OpenAI, Azure OpenAI) already return token usage metadata, and exposing it in wp-ai-client would make the library more useful for production environments where cost awareness is critical.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions