Integrations / AWS Bedrock
To trace AWS Bedrock with Tracify, record each Converse call as a step and copy the token counts from the response. Bedrock has no automatic wrapper in the SDK, so this is a few lines you write once.
Your code
AWS Bedrock
Tracify
One run.
Setup
Nothing extra beyond boto3 and the Tracify SDK.
pip install tracify-sdk boto3Create a project in Tracify, copy its API key and put it in the environment where your code runs. The SDK reads it from there, so nothing is hard-coded.
export TRACIFY_API_KEY="tracify_sk_live_..."Open a step around the call, then copy the model and the token counts from the response. If Bedrock throws an error such as throttling, the step records it and the error still reaches your code.
import boto3
import tracify
bedrock = boto3.client("bedrock-runtime")
def converse(model_id: str, prompt: str) -> str:
with tracify.span("bedrock-converse", type="llm", input=prompt) as step:
response = bedrock.converse(
modelId=model_id,
messages=[{"role": "user", "content": [{"text": prompt}]}],
)
usage = response["usage"]
text = response["output"]["message"]["content"][0]["text"]
step.set(model=model_id, input_tokens=usage["inputTokens"], output_tokens=usage["outputTokens"])
step.set_output(text)
return textThe same pattern with the AWS SDK for JavaScript.
import { BedrockRuntimeClient, ConverseCommand } from "@aws-sdk/client-bedrock-runtime";
import { span } from "tracify-sdk";
const bedrock = new BedrockRuntimeClient({});
export function converse(modelId: string, prompt: string) {
return span(
"bedrock-converse",
async (step) => {
const response = await bedrock.send(
new ConverseCommand({
modelId,
messages: [{ role: "user", content: [{ text: prompt }] }],
}),
);
step.set({
model: modelId,
inputTokens: response.usage?.inputTokens,
outputTokens: response.usage?.outputTokens,
});
return response.output?.message?.content?.[0]?.text ?? "";
},
{ type: "llm", input: prompt },
);
}Wrap your agent's entry point with trace_agent (Python) or traceAgent (TypeScript). Every Bedrock step made inside it joins the same trace, in order.
@tracify.trace_agent(name="bedrock-agent")
def run(question: str):
plan = converse("anthropic.claude-3-5-sonnet-20240620-v1:0", question)
return converse("anthropic.claude-3-5-sonnet-20240620-v1:0", plan)Run your code one time, then open the Tracing page of your project. Your Bedrock call shows up as a run with its steps in order, plus the tokens, time and any error for each call.
Good to know
The SDK wraps the OpenAI and Anthropic client shapes. Bedrock uses a different API, so there is no one-line wrapper. The step above gives you the same fields with a few lines of your own.
Good to know
If you call Claude through the Anthropic library's Bedrock client, you can wrap that client with wrap_anthropic instead and skip the manual step.
Good to know
Tracify records the tokens the provider returns. A dollar cost is shown when you give the wrapper your own rates with calculate_cost (Python) or calculateCost (TypeScript), so the number always matches your real price plan.
Full details in the documentation. All integrations are listed on the integrations page.
