Skip to main content

Log OpenAI requests

Monitor your OpenAI API calls by logging requests and responses asynchronously. Track metrics like cost, duration, and performance for all your OpenAI models including GPT-4, GPT-3.5, and more.
import requests

url = "https://api.keywordsai.co/api/request-logs/create/"
payload = {
    "model": "gpt-4o",
    "prompt_messages": [
        {
            "role": "user",
            "content": "Hello, how are you?"
        }
    ],
    "completion_message": {
        "role": "assistant",
        "content": "I'm doing well, thank you for asking!"
    },
    "cost": 0.0015,
    "generation_time": 2.3,
    "customer_params": {
        "customer_identifier": "user_123"
    }
}
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