Out-of-band observation is the safest way to start: Open Token never sits between your application and Amazon Bedrock, so nothing we do can slow down or break your traffic. You get costs, attribution and alerts; real-time enforcement (budgets and per-run limits) needs the gateway.
There are two ways in. Use either or both: the same call is never counted twice within one source.
Option A: no code (Bedrock invocation logs)
AWS cost sources is cost-only and read-only. It's separate from Connections: a Bedrock connection routes calls through Open Token, and those calls are already in the Cost explorer. This page reads the records AWS keeps in your account to add spend made outside Open Token, and needs the read-only role with log access. It never sends, blocks or changes traffic.
- In the Bedrock console, turn on Settings → Model invocation logging with S3 or CloudWatch Logs as the destination, in every region you use.
- In Integrations → Amazon Bedrock, connect your AWS account. When you create the CloudFormation stack, set Allow reading Bedrock invocation logs and the CUR to
trueand fill in the bucket or log group. The role stays read-only for these resources. - Open AWS cost sources, choose how much history to import (1 to 30 days; the default is 2) and click Find my invocation logs. We read each allowed region's logging configuration, add the sources and start importing right away; long histories continue over the next runs. After that, imports run every 15 minutes.
Late or out-of-order files and records are picked up (recent hours are re-read before they're closed), and re-reading a file never counts a call twice. If you remove a source and add it again, it resumes where it stopped.
Costs within minutes (optional)
With an S3 destination, you can have new invocation log files imported within about a minute instead of waiting for the next 15-minute run:
- On the invocation logs bucket, turn on Properties → Event notifications → Amazon EventBridge.
- Update the connection stack and set Send new invocation log files to Open Token as they arrive to
true. The stack adds an EventBridge rule that sends only the bucket name and object key of each new log file to Open Token, and a role that can do nothing else. Create that stack in us-east-1 so new files can be imported as they arrive. A stack in any other region keeps the 15-minute import.
The scheduled import keeps running as a safety net and skips files already imported this way.
The connection uses these values (the wizard fills them in for you):
Coming soon Bedrock invocation-log import is on its way. Placeholder values are marked in capitals; this snippet will fill in your real values once it ships.
Role ARN: arn:aws:iam::YOUR_ACCOUNT_ID:role/opentoken/YOUR_ROLE
External ID: YOUR_EXTERNAL_ID
Project: YOUR_PROJECT_ID
Organization: YOUR_ORG_IDWhat we read, and what we don't:
- Read: model, input, output and cache tokens, latency, region, timestamp,
requestMetadataand the calling IAM principal. - Never stored or logged: prompt and response content. The importer discards the request and response bodies while parsing, before anything is written.
Attribute spend per team, project, feature or end customer by adding requestMetadata to your Bedrock calls. Recognized keys: ot_team, ot_project (a project slug), ot_feature, ot_customer, ot_run_id and ot_env (the hyphenated spellings work too). Other keys are kept only if you allow them under Projects → Tags.
import boto3
bedrock = boto3.client("bedrock-runtime")
bedrock.converse(
modelId="us.amazon.nova-lite-v1:0",
messages=[{"role": "user", "content": [{"text": "Hello"}]}],
# Copied into your invocation logs; Open Token reads these keys for attribution.
requestMetadata={"ot_team": "payments", "ot_project": "checkout", "ot_feature": "refunds", "ot_customer": "acme"},
)Also from CloudWatch and the CUR
- AgentCore agents and X-Ray Transaction Search write GenAI spans to the
aws/spanslog group, or (newer agents) to each runtime's/aws/bedrock-agentcore/runtimes/<agent>-<endpoint>log group. Add it under AWS cost sources → Sources → CloudWatch log group (and in the stack's AgentCore / Transaction Search spans log group parameter). For runtime log groups we read only thespansstream, never the event records next to it that contain prompts. Spans become full traces under Traces (agent, model and tool steps with their cost), in the project you choose, with the same sampling, retention and content settings as OpenTelemetry traces. - Bedrock Agents: if you log the trace parts that
InvokeAgentreturns withenableTraceto a CloudWatch log group (one JSON trace part per event), add the group as Bedrock Agents traces. Each agent invocation becomes a trace with its model calls (tokens and cost), action groups, knowledge base lookups and failures; prompts, rationales and tool inputs and outputs are never read into storage. If your invocation logs are also connected, the agents' model calls are counted from the invocation logs only, so nothing is counted twice. - Cost and Usage Report (CUR 2.0, CSV): set the stack's Cost and Usage Report S3 bucket parameter and add the export in the Finance area. We read its Amazon Bedrock line items once a day (metadata only), so your AWS bill can be reconciled with what Open Token tracked.
Option B: OpenTelemetry
Most agent frameworks already emit OpenTelemetry GenAI spans (Strands Agents, Vercel AI SDK, Bedrock AgentCore) or can with auto-instrumentation (LangChain, LangGraph, LlamaIndex, the OpenAI SDK, boto3). Create a Traces API key with Traces (send) access in the service's environment and project, then point the standard exporter at Open Token:
# Load OT_INGEST_KEY from API keys → Create key → Traces → Traces (send).
export OTEL_EXPORTER_OTLP_ENDPOINT="https://getopentoken.com/api/otel"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer%20${OT_INGEST_KEY}"
export OTEL_SERVICE_NAME="my-agent"
# Open Token ingests traces only: keep metrics and logs off so they are not exported here.
export OTEL_METRICS_EXPORTER="none"
export OTEL_LOGS_EXPORTER="none"
# Optional attribution on every span of this service:
export OTEL_RESOURCE_ATTRIBUTES="opentoken.team=payments,opentoken.feature=checkout"Run your service with auto-instrumentation:
pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install
# Exports traces in the background with a bounded queue; if we're unreachable, spans are dropped, never your requests.
opentelemetry-instrument python app.pyBoth OTLP encodings work (http/protobuf and http/json, gzip optional). The usage meter reads model, token and attribution attributes. It does not use span events for cost. Trace storage keeps each event's name, time and attributes that are not content. Prompts, responses and tool arguments are stored only when the project turns capture on and the plan allows it. Leave that content out unless you mean to store it.
To trace one call from a TypeScript app or editor extension, see Trace LLM calls with OpenTelemetry in Node.js.
Your exporter must never block your app
The OpenTelemetry SDKs export from a bounded in-memory queue on a background thread. If Open Token is slow or unreachable, the queue fills and new spans are dropped; your requests never wait. Keep it that way:
# Batch span processor: a bounded in-memory queue exported in the background.
# When the queue is full new spans are dropped; your requests never wait on the exporter.
export OTEL_BSP_MAX_QUEUE_SIZE=2048
export OTEL_BSP_MAX_EXPORT_BATCH_SIZE=512
export OTEL_BSP_SCHEDULE_DELAY=5000
export OTEL_BSP_EXPORT_TIMEOUT=10000
export OTEL_EXPORTER_OTLP_TIMEOUT=10000- Use the batch span processor (the default with auto-instrumentation), never the simple/synchronous one.
- Keep the export timeout short (10 s or less). Exporters retry
429and503responses with backoff; retries are safe because each span is counted once. - Limits per ingest key: 4 MB per request (16 MB after gzip), 10,000 spans per request, and a per-second span rate by plan. Over the rate you get
429withRetry-After.
Import health
AWS cost sources → Sources shows, for each source, its health (healthy, catching up, retrying, stalled or paused), how far behind the import is, the newest record imported and how many unreadable records were skipped. If a source stalls (no successful import for an hour, four failed runs in a row, or more than two hours behind), owners and admins get one email, and one more when it recovers.
Alerts and forecast
In AWS cost sources → Alerts, set thresholds for daily spend, month-to-date spend or the month-end forecast, for the whole organization or one project. Alerts go to owners, admins and Finance members by email and, optionally, to a webhook signed with x-opentoken-signature: t=<unix>,v1=<hex HMAC-SHA256 of "t.body">. Each alert fires at most once per day or month.
Next
- Ready for enforcement? See the gateway quickstart.
- Critical, high-volume traffic: follow the high-volume onboarding runbook.