Skip to main content

Log Gemini requests

Monitor your Google Gemini API calls by logging requests and responses asynchronously. Track metrics like cost, duration, and performance for Gemini’s multimodal capabilities.
import requests

url = "https://api.keywordsai.co/api/request-logs/create/"
payload = {
    "model": "gemini-1.5-flash",
    "prompt_messages": [
        {
            "role": "user",
            "content": "Describe the image and suggest improvements"
        }
    ],
    "completion_message": {
        "role": "assistant",
        "content": "The image shows a modern office space with clean lines..."
    },
    "cost": 0.0006,
    "generation_time": 2.8,
    "customer_params": {
        "customer_identifier": "user_707"
    }
}
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