Skip to main content

Real-time token usage and cost monitoring for AWS Bedrock

Project description

bedrock-lens

Real-time token usage and cost monitoring for AWS Bedrock — because Cost Explorer won't tell you until tomorrow.

Model Calls Input Tokens Output Tokens Total Tokens Est. Cost
Claude Opus 4 2 12,540 3,812 16,352 $0.4746
Claude Sonnet 4 14 48,300 11,220 59,520 $0.3132
Claude Haiku 4 38 63,807 9,441 73,248 $0.0888
Llama 3.1 70B 5 4,200 1,830 6,030 $0.0060
TOTAL 59 128,847 26,303 155,150 $0.8826

The problem

When running Bedrock agents, you're flying blind. AWS Cost Explorer has a 24–48 hour lag. CloudWatch has live data, but getting to it requires knowing the log group name, converting dates to epoch milliseconds, parsing deeply nested JSON, and doing the cost math yourself.

There's no bedrock usage command. This is that command.

Install

uv tool install git+https://github.com/OmarCodes022/bedrock-lens

Or from source:

git clone https://github.com/OmarCodes022/bedrock-lens
cd bedrock-lens
uv tool install .

Usage

bedrock-usage                        # today's usage (default)
bedrock-usage --yesterday
bedrock-usage --week
bedrock-usage --since 2h             # last 2 hours
bedrock-usage --since 30m            # last 30 minutes
bedrock-usage --since 1d             # last 1 day
bedrock-usage --live                 # tail mode, refreshes every 5s
bedrock-usage --since 1h --live      # live tail for the last hour
bedrock-usage --live --threshold 2   # alert when spend crosses $2
bedrock-usage --setup                # one-time setup wizard
# different profile / region
bedrock-usage --profile my-profile --region us-west-2

First-time setup

Bedrock doesn't log invocations by default. Run the setup wizard once per AWS account:

bedrock-usage --setup

This creates the CloudWatch log group, an IAM role for Bedrock to write to it, and enables model invocation logging. Takes about 10 seconds. After that, every Bedrock call shows up within ~30 seconds.

If you don't have IAM permissions to create roles, the wizard prints the exact policies and CLI command to hand off to your admin.

How it works

Bedrock writes a JSON record to /aws/bedrock/model-invocations in CloudWatch for every model call. Each record contains the model ID, input token count, and output token count. bedrock-lens reads those records, applies per-model pricing, and renders the table.

Live mode (--live) polls every 5 seconds with a 90-second overlap window to handle CloudWatch's ingestion delay, deduplicating events by ID so nothing gets double-counted.

Supported models

Claude (Haiku, Sonnet, Opus — v3 through v4), Amazon Titan, Meta Llama 3 / 3.1 / 3.2, Mistral, Mixtral, Cohere Command R / R+, AI21 Jamba.

Pricing is per the AWS on-demand rates for us-east-1. Unknown models show N/A for cost but still display token counts.

Requirements

  • Python 3.9+
  • AWS credentials with logs:FilterLogEvents on /aws/bedrock/model-invocations
  • Bedrock model invocation logging enabled (run --setup if not)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bedrock_lens-0.1.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bedrock_lens-0.1.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file bedrock_lens-0.1.0.tar.gz.

File metadata

  • Download URL: bedrock_lens-0.1.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for bedrock_lens-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9e59651f037e378f114ad71f2945a32708890ca962e0b607145a811ce9928323
MD5 585e2243536b24bd7b4047297b5ff107
BLAKE2b-256 e9d487581c2875f3f0398d7028a2258e393df63aa1be17c3d12ce30c8ed5497a

See more details on using hashes here.

File details

Details for the file bedrock_lens-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bedrock_lens-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for bedrock_lens-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f22ab827592a76854719dcfcc0a12ee586c70aa71035390f881de9cb23fdb3c
MD5 c7abb0e7330efab63871437b58b2ccd6
BLAKE2b-256 baceb2d71ae2f542eab199b10dd72b2798360f3f93e37ba2e4599cf325b3bc88

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page