AWS Bedrock
JournaledBedrock — drop-in wrapper around boto3 Bedrock that journals every invocation.
Usage
import boto3
from tokenid import JournaledBedrock
bedrock = JournaledBedrock(
boto3.client("bedrock-runtime", region_name="us-east-1"),
session_id="my-session",
)
resp = bedrock.invoke_model(
modelId="anthropic.claude-sonnet-4-20250514-v1:0",
body=b'{"messages":[{"role":"user","content":"Hello"}],"max_tokens":256,"anthropic_version":"bedrock-2023-05-31"}',
)
JournaledBedrock wraps bedrock-runtime and forwards every call. Token counts and cost are journaled
to TokenID after the response returns. Works for both Anthropic Claude on Bedrock and Amazon Nova models.
Streaming
events = bedrock.invoke_model_with_response_stream(
modelId="anthropic.claude-sonnet-4-20250514-v1:0",
body=b'...',
)
for ev in events["body"]:
...
Token counts are aggregated across the final stream chunk and journaled on completion.
Cost basis
Bedrock pricing is parsed from the response metadata (inputTokenCount / outputTokenCount).
For Nova models the parser also falls back to the body-level usage.inputTokens / usage.outputTokens.
Pulling historical usage
To backfill historical Bedrock usage from CloudWatch Model Invocation Logs, configure an
AWS connection in the TokenID dashboard with an IAM key that has logs:StartQuery and
logs:GetQueryResults on the /aws/bedrock/modelinvocations log group. The puller queries
Logs Insights every hour and normalises every invocation into the events ledger.