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 5 48,200 14,300 62,500 $1.7955
Claude Sonnet 4.6 22 182,400 43,100 225,500 $1.3131
Claude Haiku 4.5 91 310,500 38,200 348,700 $0.5516
Llama 3.1 70B 12 28,400 9,800 38,200 $0.0173
DeepSeek V3.1 8 41,200 12,600 53,800 $0.0451
TOTAL 138 610,700 118,000 728,700 $3.7226

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

pip install bedrock-lens

Or with uv:

uv tool install bedrock-lens

Usage

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

All models available on Amazon Bedrock are displayed with token counts. Cost estimation works as follows:

Live pricing (via AWS Price List API): Llama 3 / 3.1 / 3.2 / 3.3 / 4, Mistral, Mixtral, DeepSeek, Gemma, Qwen3, Nova, Kimi, MiniMax, Nemotron, GLM, and 50+ others. Prices are fetched at runtime for your region, so they stay up to date automatically.

Hardcoded fallback: Claude (Haiku, Sonnet, Opus — v3 through v4), Amazon Titan, Cohere Command R / R+, AI21 Jamba. AWS hasn't added these to the Price List API yet, so prices are bundled with the tool and updated on each release.

Token counts are always accurate for every model — they come directly from CloudWatch logs written by Bedrock itself. Only cost estimation depends on the pricing source; unknown models show N/A for cost but tokens are never affected.

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.3.tar.gz (12.3 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.3-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bedrock_lens-0.1.3.tar.gz
  • Upload date:
  • Size: 12.3 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.3.tar.gz
Algorithm Hash digest
SHA256 b2fb196519dd5b97b91ae562669cdca57c0b4c63e08239860b2f6c99019335b4
MD5 414c3b06957add36d7fb799da6288cfe
BLAKE2b-256 bdcc1b8598a92130e972d6d57b9f24df9309060c505d9a5c2bbb996b6b2ff0c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bedrock_lens-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 16.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d85d1d34a87ee2c7444fbfe8eac431d149cb1bad7c924e433a4159112b367c0f
MD5 253799a27313c09e12c41d27593e36ad
BLAKE2b-256 7b4708f49d4f0ab63be9f2b102e4426e5466565d9fbfc711fc58edffdf8eb1a0

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