AWS Bedrock

Auto-instrument AWS Bedrock. Every Converse, InvokeModel, and ConverseStream call inside an active run emits an llm_call event with model, token usage, and latency. Cost is computed server-side from the rate card. Bedrock fronts many model families (Anthropic, Meta, Mistral, Amazon, Cohere) behind one API.

Install / enable

Python:

pip install 'agentping-sdk[bedrock]'
import boto3
import agentping

agentping.init()
agentping.instrument_bedrock()

client = boto3.client("bedrock-runtime", region_name="eu-west-2")

with agentping.run("order-classifier"):
    response = client.converse(
        modelId="eu.anthropic.claude-sonnet-4-5-20250929-v1:0",
        messages=[{"role": "user", "content": [{"text": "classify this order"}]}],
    )

instrument_bedrock() patches botocore once and filters to the bedrock-runtime service. Converse, InvokeModel, and ConverseStream are captured; non-Bedrock AWS clients are untouched.

TypeScript:

npm install @agentping/sdk @aws-sdk/client-bedrock-runtime
import * as agentping from "@agentping/sdk";
import {
  BedrockRuntimeClient,
  ConverseCommand,
} from "@aws-sdk/client-bedrock-runtime";

agentping.init();

const client = agentping.instrumentBedrock(
  new BedrockRuntimeClient({ region: "eu-west-2" }),
);

await agentping.runScopeAsync(agentping.run("order-classifier"), async () => {
  await client.send(
    new ConverseCommand({
      modelId: "eu.anthropic.claude-sonnet-4-5-20250929-v1:0",
      messages: [{ role: "user", content: [{ text: "classify this order" }] }],
    }),
  );
});

instrumentBedrock(client) returns a Proxy that detects ConverseCommand, ConverseStreamCommand, InvokeModelCommand, and InvokeModelWithResponseStreamCommand by constructor name; other commands (e.g. ListFoundationModelsCommand) pass through and emit no event.

What's captured

Model, input tokens, output tokens, and latency. Use the inference profile ID as modelId (e.g. eu.anthropic.claude-sonnet-4-5-20250929-v1:0); the rate card resolves it to the underlying model and the region prefix is preserved so you can pivot Spend by region. Prompt caching is captured separately: when Bedrock returns cacheReadInputTokens, the cached portion is split into cached_input_tokens.

Streaming

Automatic. ConverseStream is wrapped: Bedrock emits a metadata chunk carrying the final usage block, captured whether you drain the stream fully or break early, and one llm_call fires on close.

with agentping.run("stream-converse"):
    response = client.converse_stream(
        modelId="eu.anthropic.claude-sonnet-4-5-20250929-v1:0",
        messages=[{"role": "user", "content": [{"text": "..."}]}],
    )
    for event in response["stream"]:
        if "contentBlockDelta" in event:
            print(event["contentBlockDelta"]["delta"]["text"], end="")

Source / notes

The rate card carries Claude (Anthropic), Llama (Meta), Mistral, Cohere Command, and Amazon Titan / Nova prices for Bedrock. Custom-imported and bring-your-own models land unpriced; set their per-token cost in rate card overrides.