Guide
AWS Bedrock cost tracking by customer, feature and team
Published
Your AWS bill tells you what Amazon Bedrock cost. It doesn't tell you which customer, product feature or team the spend served. This guide shows how to record Bedrock costs at that level from your own code, including on AWS Lambda, check the figures against Cost Explorer, and avoid the token-counting mistake that makes Bedrock input look cheaper than it is.
What does AWS show about Bedrock spend, and what's missing?
AWS Cost Explorer reports Bedrock spend per day, and can split it by a cost allocation tag you have activated, such as project or team. CloudWatch holds token usage per model. Neither knows which of your customers a call served or which product feature made it.
Provider bills and usage exports have no customer field. They can tell you a model cost $4.02 today, not whether that was one customer running a heavy report or a thousand customers sending one message each. The only moment that information exists is when your code makes the call, so that is where tracking has to start.
How do you track Bedrock costs per customer, feature and team?
Wrap your Bedrock runtime client with the Token Meter SDK, then open an action() scope that names the customer, feature and team around the calls it covers. For Bedrock this is the way to tag calls made on your own AWS account. The router can't carry them (see the note below).
Install pip install "tokenmeter-sdk[bedrock]" or npm install @tokenmeter/sdk @aws-sdk/client-bedrock-runtime. Bedrock uses your usual AWS credentials, not an API key. The role your code runs as needs bedrock:InvokeModel, plus bedrock:InvokeModelWithResponseStream for streaming.
import { BedrockRuntimeClient, ConverseCommand } from "@aws-sdk/client-bedrock-runtime";
import { TokenMeterClient, wrapBedrock, action } from "@tokenmeter/sdk";
const tl = new TokenMeterClient({ apiKey: process.env.TOKEN_METER_KEY ?? "" });
// Uses your usual AWS credentials (environment variables, ~/.aws or an IAM role).
const bedrock = wrapBedrock(new BedrockRuntimeClient({ region: "us-east-1" }), tl);
const reply = await action("generate-report", { customerRef: "acme", feature: "reports", team: "growth" }, () =>
bedrock.send(
new ConverseCommand({
modelId: "amazon.nova-lite-v1:0",
messages: [{ role: "user", content: [{ text: "Say hello in five words." }] }],
}),
),
);
console.log(reply.output.message.content[0].text);
await tl.flush();Usage is read from the reply Bedrock already sent, so there is no proxy and no extra network hop, and the SDK never throws into your code during a call. Events are sent in the background every 2 seconds; short scripts call tokenmeter.flush() or await tl.flush() before exiting. The tags show as the Customer and Team columns on Requests, and customer cost feeds Customers. Use ids such as cus_123 for customers, not email addresses: emails are redacted and merge into one row.
If you call Claude through Anthropic's AnthropicBedrock client, wrap it the same way (wrapAnthropic in TypeScript); its calls are recorded under AWS Bedrock, because that is the bill they appear on. Calls through the Vercel AI SDK's @ai-sdk/amazon-bedrock provider are recorded as Bedrock by the SDK's middleware, from SDK 0.2.1.
The router can't carry your own Bedrock account
Token Meter's router stores your own inference key only for OpenAI, Anthropic and Google (a Gemini API key from Google AI Studio). There is no option to store Bedrock credentials. Amazon Bedrock appears in the router only as one of the endpoints that serve Claude models on Token Meter's own AWS accounts, used for auto routing on paid plans or when a workspace pays from Token Meter credits. A request that names a model is never sent to those accounts otherwise. So the router is not a way to meter traffic billed to your AWS account: use the SDK wrapper for that, and the Cost Explorer connection below for the bill.
Details: Providers, Attribution and Gateway and routing. To turn per-customer cost into margin, see LLM cost per customer.
How do you record Bedrock calls from AWS Lambda?
Send the usage yourself as the last line before the handler returns. Lambda freezes your code as soon as the handler finishes, so the SDK's background send every 2 seconds may never run. In TypeScript, also create the client with createServerlessClient, which turns the background timer off.
import { BedrockRuntimeClient, ConverseCommand } from "@aws-sdk/client-bedrock-runtime";
import { createServerlessClient, flushBeforeReturn, wrapBedrock } from "@tokenmeter/sdk";
const tl = createServerlessClient({ apiKey: process.env.TOKEN_METER_KEY ?? "" });
const bedrock = wrapBedrock(new BedrockRuntimeClient({ region: "us-east-1" }), tl);
export const handler = async (event) => {
const reply = await bedrock.send(
new ConverseCommand({
modelId: "amazon.nova-lite-v1:0",
messages: [{ role: "user", content: [{ text: event.prompt ?? "Say hello" }] }],
}),
);
await flushBeforeReturn(tl); // the last line before return
return { statusCode: 200, body: reply.output.message.content[0].text };
};In Python, tokenmeter.flush(deadline_s=2.0) keeps sending until nothing is left, 2 seconds pass, or a send fails. In Node.js, if you use the older callback style, leave callbackWaitsForEmptyEventLoop at its default (true). The TypeScript SDK works on AWS Lambda with Node.js 20.6 or later. Usage recorded after the last flush of a request is lost. See Frameworks and runtimes.
How do you check the figures against your AWS bill?
Connect your AWS account through Cost Explorer with a cross-account IAM role. Token Meter then imports Bedrock spend per day and compares it, day by day, with the cost it metered from your calls. A day matches when the two are within 2% of the invoice. No AWS keys are shared, and the role can only read billing and usage data.
- Turn on Cost Explorer: open Billing and Cost Management › Cost Explorer once, and allow up to 24 hours for data to appear.
- In Token Meter, open Settings › Connections, choose Connect an account and pick Bedrock as the Provider. Owners and Admins can do this. The form shows Your External ID, the Trust policy and the Permissions policy. Keep it open.
- In the AWS console, open IAM › Roles, choose Create role, pick Custom trust policy and paste the form's trust policy. Skip the managed policies and name the role
TokenMeterBilling. - On the new role, choose Add permissions › Create inline policy, switch to JSON, paste the permissions policy and save it as
TokenMeterBillingRead. - Copy the role's ARN. Back in the form, enter your 12-digit AWS account ID (the one inside the ARN) and paste the Cross-account role ARN. Choose Connect and sync.
The permissions policy needs ce:GetCostAndUsage, which reads Bedrock spend per day. ce:GetTags is optional and also splits spend by an activated cost allocation tag. cloudwatch:ListMetrics and cloudwatch:GetMetricData are optional and read token usage per model in 15 default AWS regions; without them billing still works.
The trust policy only lets Token Meter's AWS account assume the role with your External ID. On the first sync, and then at most once a day, Token Meter also tries the role with a wrong External ID; if AWS lets it in, it refuses to use the role. Each check leaves one refused AssumeRole attempt in CloudTrail with the session name token-meter-externalid-check.
The first sync imports the last 7 days, and the rest of the history, up to 90 days, follows in the background. Bedrock then syncs once a day. Days are UTC, today is never requested, and providers take a few days to settle their figures. Reconciliation runs at 07:00 UTC and compares each day at the first run after a 3-day settlement delay, so a fresh connection shows Not reconciled yet at first.
Bedrock then shows Matched when every reconciled day in the range is within 2%, and Drift detected when at least one day differs by more.
- Create the role in the account whose Bedrock bill you want. In AWS Organizations, a member account sees only its own costs in Cost Explorer.
- AWS charges $0.01 per Cost Explorer API request. Each daily sync makes 1 to 3, about $1 a month; with a tag split, at most about $7 a month.
- Invoice dollars for Bedrock models other than Claude show as Unmapped spend: they are not tied to a model.
- For a negotiated rate, add a private rate (Settings › Connections, Advanced, Add a private rate). A start date up to 365 days back reprices usage from that day.
On Analytics › Bill, once Bedrock invoice lines exist for a range, the invoice is what counts toward your total AI spend, never the invoice plus metered cost. See AI Bill and billing imports, and tracking AI spend across providers if Bedrock is one of several bills.
Which Bedrock calls are recorded, and how are the tokens counted?
Converse and ConverseStream are fully recorded for every model family, in Python and TypeScript, so prefer them. InvokeModel is recorded too, but its response body differs by model family, and the two languages read different families.
| Call | Python | TypeScript |
|---|---|---|
| Converse, ConverseStream | Fully recorded, every family | Fully recorded, every family |
| InvokeModel: Anthropic Claude, Amazon Nova | Body read | Body read when the model id starts with anthropic. or amazon.nova; Nova cache counts left empty |
| InvokeModel: Meta Llama | Body read | Recorded as incomplete, with no token counts |
| InvokeModel: any other family, Mistral included | Counts from the x-amzn-bedrock-input-token-count and x-amzn-bedrock-output-token-count headers | Recorded as incomplete, with no token counts: the AWS SDK for JavaScript doesn't expose those headers |
| InvokeModelWithResponseStream | Input and output only, no cache split | Input and output only, no cache split |
In Python, the InvokeModel body is read in memory and handed back as a fresh stream, so your own response["body"].read() still works. Python wraps the regular boto3 client; aioboto3 is not recorded yet. In TypeScript, InvokeModel picks the body reader from the start of the model id, so an inference profile id such as us.anthropic.claude-… is recorded as incomplete; Converse has no such limit. The TypeScript wrapper also recognises ConverseCommand and the other commands by class name, so if your build minifies code, keep class names (for example esbuild's keepNames: true).
Bedrock's inputTokens already leaves out the cache
OpenAI teaches the habit "cache and reasoning tokens are part of the total, so subtract them". Bedrock's Converse response works the other way: inputTokens already leaves out cache reads and writes. Subtracting cacheReadInputTokens from it takes the cache off twice, and input spend comes out too low. Token Meter uses inputTokens as it is.
Bedrock has no reasoning count: Claude thinking tokens are billed inside outputTokens, so they are priced as output and not shown separately. The Converse shape is documented by AWS. For Amazon Nova through InvokeModel, AWS's own documents disagree on how the cache counts are spelled, so Python checks every spelling and TypeScript leaves Nova cache counts empty rather than guess. A count Bedrock doesn't report stays empty; it is never guessed.
How do you cap Bedrock spend?
Set a budget: a monthly spend limit on the whole workspace or on one customer, feature, action, team, environment, provider or model, with alerts as spend climbs. Budgets are checked every 60 seconds against month-to-date spend for the UTC calendar month, from every connected usage source, including the Bedrock calls the SDK records. They warn; they can't stop a Bedrock call your code makes straight to AWS.
- Budgets. Thresholds default to 50%, 80% and 100%, each firing once a month, and a projection alert warns when the month's linear burn will go over. Owners and Admins create them under Governance › Budgets. On the Free plan you can set one advisory, workspace-wide budget; scoped budgets, alert rules and notification channels need a paid plan.
- Alert rules. A Threshold rule fires when spend for a scope, optionally limited to one provider and model, reaches an amount within the UTC day or month. A Provider spike rule fires when today's spend so far reaches a set multiple of yesterday's, scaled to the part of the day that has passed. Alerts go to email, Slack or Discord channels.
- Stopping calls. Enforced budgets only stop router traffic, and direct Bedrock calls never pass through the router. To check a direct call before it runs, use governance preflight, which asks the router whether the call is allowed under your governance policies (not your budgets) and adds one round trip. Provider-side enforcement on Governance › Rules can also turn your workspace-wide policies (those with no team or environment scope) into an AWS Organizations SCP for Bedrock. It limits which models can be called; it is not a spend cap. Review it before you apply it, because wildcard ARNs can match more than the exact model names.
What doesn't this cover?
- Traffic billed to your own AWS account can't be sent through the Token Meter router, so routing, caching and router-enforced limits don't apply to it.
- Bedrock calls that don't go through a wrapped client or the Vercel AI SDK middleware carry no customer or feature. With Cost Explorer connected, their spend still shows in the imported Bedrock totals.
- In TypeScript,
InvokeModelbodies are read only for Claude and Nova model ids (not inference profile ids), and other families, such as Meta Llama and Mistral, are recorded with no token counts.aioboto3in Python is not recorded yet. InvokeModelWithResponseStreamrecords no cache split, and reasoning tokens are never reported separately.- Invoice dollars for Bedrock models other than Claude aren't tied to a model.
- Invoice figures are not live: today is never imported, and the newest days can lag while AWS settles them.
Start tracking Bedrock costs
Create a workspace, add an ingest key, wrap your Bedrock runtime client and tag one call with a customer and feature. Then connect Cost Explorer with a read-only role to check the metered cost against your AWS bill.