Skip to content

Expose Bedrock token usage in InvokeModel response metadata #8172

Description

@vedant0745

Describe the feature

When using Amazon Bedrock, some models do not support the CountTokens API (for example, cohere.embed-v4:0). For these models, applications still need a reliable way to obtain the exact input/output token counts after an InvokeModel request for purposes such as usage metering, billing, quotas, and analytics.

Currently, token counts may be available as HTTP response headers (e.g. x-amzn-bedrock-input-token-count and x-amzn-bedrock-output-token-count), but accessing these headers is not straightforward or consistent across SDKs and versions.

Feature Request

Please expose token usage returned by the Bedrock service through a stable, documented SDK interface.

For example, one of the following would be helpful:

response.$metadata.tokenUsage = {
  inputTokens: number;
  outputTokens: number;
};

or

response.tokenUsage = {
  inputTokens: number;
  outputTokens: number;
};

The exact shape is less important than having a documented and supported way to access this information without relying on raw HTTP headers.

If exposing these values is not possible because the Bedrock service does not guarantee these headers, clarification in the documentation would also be appreciated.

Use Case

Applications integrating Amazon Bedrock often need exact per-request token usage to:

Track tenant usage
Attribute costs
Enforce usage quotas
Build usage analytics

Today, this is difficult for models that do not support CountTokens, as applications must rely on transport-specific behavior instead of a supported SDK interface.

Proposed Solution

If the Bedrock service already returns token usage information, expose it through a typed field on the InvokeModel response or within $metadata.

If the service does not currently return this information in a guaranteed way, consider exposing it as part of the service response so SDKs can surface it consistently across languages.

Other Information

CountTokens is not supported for all Bedrock models (for example, cohere.embed-v4:0).

This feature would provide a consistent SDK experience across models and eliminate the need for applications to depend on undocumented HTTP response headers or custom middleware.

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

SDK version used

@aws-sdk/client-bedrock-runtime@3.1079.0

Environment details (OS name and version, etc.)

  • OS: macOS Tahoe (Apple Silicon M4) - Runtime: Node.js v24 - Language: TypeScript

Metadata

Metadata

Assignees

Labels

feature-requestNew feature or enhancement. May require GitHub community feedback.p3This is a minor priority issueservice-apiThis issue is due to a problem in a service API, not the SDK implementation.

Type

No type

Fields

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