Skip to main content

Log AWS Bedrock requests

Monitor your AWS Bedrock API calls by logging requests and responses asynchronously. Track metrics like cost, duration, and performance for Bedrock’s foundation models.
import requests

url = "https://api.keywordsai.co/api/request-logs/create/"
payload = {
    "model": "anthropic.claude-3-sonnet-20240229-v1:0",
    "prompt_messages": [
        {
            "role": "user",
            "content": "Generate a product description for an eco-friendly water bottle"
        }
    ],
    "completion_message": {
        "role": "assistant",
        "content": "Introducing the EcoFlow bottle - a sustainable hydration solution..."
    },
    "cost": 0.0009,
    "generation_time": 3.2,
    "customer_params": {
        "customer_identifier": "user_808"
    }
}
headers = {
    "Authorization": "Bearer YOUR_KEYWORDS_AI_API_KEY",
    "Content-Type": "application/json"
}

response = requests.post(url, headers=headers, json=payload)

Get Started with Logging

Learn how to set up comprehensive logging for all your LLM requests
I