POST
/
api
/
request-logs
/
batch
/
create

The batch logging endpoint allows you to log multiple requests at once. This is useful for logging multiple requests in a single call.

You can log up to 5000 requests at once, and the maximum size of the request is 100MB.

Example call

import requests
import os

URL = "https://api.keywordsai.co/api/request-logs/batch/create"
API_KEY = os.getenv("KEYWORDS_AI_API_KEY_PRODUCTION")


response = requests.post(
    URL,
    headers={"Authorization": "Bearer " + API_KEY},
    json={
        "logs": [
            {
                "cost": 0,
                "prompt_messages": [
                    {
                        "role": "user",
                        "content": [
                            {"type": "text", "text": "Sixth message"},
                            {
                                "type": "image_url",
                                "image_url": {
                                    "url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/"
                                },
                            },
                        ],
                    },
                    {
                        "role": "assistant",
                        "content": None,
                        "tool_calls": [
                            {
                                "id": "call_p2RIiNv3B8JF8Capaz3vA7kZ",
                                "type": "function",
                                "function": {
                                    "name": "transfer_call",
                                    "arguments": '{"execution_message":"I\'m sorry to hear that. Let me transfer you to a human representative for further assistance."}',
                                },
                            }
                        ],
                    },
                ],
                "completion_message": {
                    "role": "assistant",
                    "content": "Hi, How can I assist you today?",
                    "tool_calls": None,
                },
                "tool_calls": [
                    {
                        "id": None,
                        "function": {"arguments": '"}', "name": None},
                        "type": "function",
                        "index": 0,
                    }
                ],
                "tool_choice": {
                    "type": "function",
                    "function": {"name": "get_current_weather"},
                },
                "latency": 10,
                "time_to_first_token": 0.1,
                "model": "claude-3-5-sonnet-20240620",
                "timestamp": "2024-04-15T08:30:37.721313Z",
                "metadata": {"key2": "1"},
                "stream": True,
                "status_code": 401,
                "warnings": "Test log",
                "error_message": "",
                "customer_identifier": "a_model_customer",
                "keywordsai_params": {"customer_identifier": "b_model_customer"},
            }
        ]
    },
)

print(response.json())