Skip to content

feat(bedrock): add request_metadata for per-request cost attribution#2338

Open
psantus wants to merge 1 commit into
strands-agents:mainfrom
psantus:feat/request-metadata
Open

feat(bedrock): add request_metadata for per-request cost attribution#2338
psantus wants to merge 1 commit into
strands-agents:mainfrom
psantus:feat/request-metadata

Conversation

@psantus
Copy link
Copy Markdown

@psantus psantus commented May 27, 2026

Description

Add request_metadata config option to BedrockModel that maps to the requestMetadata field in Converse/ConverseStream API requests.

This enables per-request finops by attaching key-value tags (e.g. team, environment, feature) that appear in model invocation logs.

Default behavior is unchanged — no metadata is sent unless explicitly configured.

Usage

model = BedrockModel(
    model_id="anthropic.claude-sonnet-4-20250514",
    request_metadata={"team": "orchestrator", "environment": "prod"}
)

# Or update per-conversation:
model.update_config(request_metadata={"team": "billing", "session_id": "abc123"})

Reference

https://docs.aws.amazon.com/bedrock/latest/userguide/cost-mgmt-request-metadata.html

What was tested

  • test_format_request_with_request_metadata — metadata included when configured
  • test_format_request_without_request_metadata — backward compat (no key when unset)
  • Full bedrock test suite (168 tests) passes with no regressions

…ibution

Add request_metadata config option to BedrockModel that maps to the
requestMetadata field in Converse/ConverseStream API requests. This
enables per-request finops by attaching key-value tags (e.g. team,
environment, feature) that appear in model invocation logs.

Default behavior is unchanged (no metadata sent). When set, the dict
is passed as-is to the Bedrock API.

Ref: https://docs.aws.amazon.com/bedrock/latest/userguide/cost-mgmt-request-metadata.html
@psantus psantus requested a deployment to manual-approval May 27, 2026 08:36 — with GitHub Actions Waiting
@psantus psantus requested a deployment to manual-approval May 27, 2026 08:36 — with GitHub Actions Waiting
@yonib05 yonib05 added area-provider Related to model providers enhancement New feature or request python Pull requests that update python code labels May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-provider Related to model providers enhancement New feature or request python Pull requests that update python code size/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants