Integrate Langtrace with AWS Bedrock

Obinna Okafor

Software Engineer

Oct 24, 2024

Bedrock x Langtrace
Bedrock x Langtrace
Bedrock x Langtrace

Introduction

AWS Bedrock is Amazon's fully managed service that offers a choice of high-performing foundation models through a single API. It provides access to leading models from Anthropic, AI21 Labs, Cohere, Meta, and Amazon's own models, making it an excellent choice for enterprises looking to build generative AI applications. Bedrock stands out for its enterprise-grade security, scalability, and seamless integration with other AWS services. Its pay-as-you-go pricing model and built-in model monitoring make it particularly attractive for production deployments.

We are excited to announce that Langtrace now supports AWS Bedrock natively. This means:

  • If you are using AWS Bedrock, you can set up Langtrace to automatically capture metrics such as token usage, cost, latency, and request metadata.

  • You can monitor your Bedrock model performance across different models.

  • Get detailed insights into your AWS Bedrock usage patterns and optimization opportunities.


Setup

  1. Sign up to Langtrace, create a project and get a Langtrace API key

  2. Install the Langtrace SDK

pip install -U langtrace-python-sdk
  1. Setup the environment variable

export LANGTRACE_API_KEY=YOUR_LANGTRACE_API_KEY
  1. Initialize Langtrace in your code

import os
from langtrace_python_sdk import langtrace

langtrace.init(api_key=os.environ['LANGTRACE_API_KEY'])

# Your AWS Bedrock code here
  1. Configure AWS credentials

import boto3

bedrock = boto3.client(
    'bedrock-runtime',
    region_name='us-east-1',
    aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"],
    aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"],
)


View traces in your Langtrace dashboard


Once set up, you can monitor your AWS Bedrock usage in real-time through the Langtrace dashboard. You'll be able to:

  • Track token usage across different Bedrock models

  • Monitor response times and costs

  • Analyze request patterns and optimization opportunities

  • Set up alerts for unusual patterns or cost thresholds

Useful Resources


Ready to try Langtrace?

Try out the Langtrace SDK with just 2 lines of code.

Ready to deploy?

Try out the Langtrace SDK with just 2 lines of code.

Want to learn more?

Check out our documentation to learn more about how langtrace works

Join the Community

Check out our Discord community to ask questions and meet customers