Skip to main content
POST
https://api.keywordsai.co
/
api
/
request-logs
/
summary
import requests

url = "https://api.keywordsai.co/api/request-logs/summary/"
headers = {
    "Authorization": f"Bearer {YOUR_KEYWORDS_AI_API_KEY}",
    "Content-Type": "application/json"
}
params = {
    "start_time": "2025-12-01T00:00:00Z",
    "end_time": "2025-12-31T23:59:59Z"
}
data = {
    "filters": {
        "model": {
            "operator": "",
            "value": ["gpt-4o"]
        }
    }
}

response = requests.post(url, headers=headers, params=params, json=data)
print(response.json())
{
  "summary": {
    "total_cost": 15.67,
    "total_tokens": 1250000,
    "number_of_requests": 8453
  }
}
The Logs Summary endpoint returns aggregated statistics for logs matching the given filters. This is useful for getting quick insights into your LLM usage without fetching all individual logs.
Both GET and POST methods are supported. POST is recommended when using complex filters.

Query parameters

Same parameters as the List Logs endpoint:
start_time
string
The start time for filtering logs in ISO 8601 format. If not provided, defaults to 1 hour ago.
{
  "start_time": "2025-08-15T00:00:00Z"
}
end_time
string
The end time for filtering logs in ISO 8601 format. If not provided, defaults to current time.
{
  "end_time": "2025-08-16T00:00:00Z"
}
all_envs
string
default:"false"
Whether to include logs from all environments. is_test parameter will override this parameter. Options: true, false.
is_test
string
default:"false"
Whether to include test logs only. This parameter will override the all_envs parameter. Options: true, false.

Body parameters

You can add filter parameters to the request body (same as List Logs endpoint):
filters
object
The filters to be applied to the logs.
If you want to filter your custom properties, add metadata__ + your custom property name. For example, to filter my_custom_property, use metadata__my_custom_property.For a complete list of filter operators and examples, see the Filters API Reference.
  {
    "model": {
      "operator": "",
      "value": ["gpt-4o"]
    },
    "cost": {
      "operator": "gte",
      "value": [0.01]
    }
  }

URL-based Filtering

Just like the List Logs endpoint, you can use URL parameters for quick filtering:
# Filter summary by customer
GET /api/request-logs/summary/?customer_identifier=user_123

# Filter by custom metadata
GET /api/request-logs/summary/?user_tier=premium&department=sales
See the List Logs endpoint for complete URL filtering documentation.

Response

summary
object
Aggregated statistics for the filtered logs.
import requests

url = "https://api.keywordsai.co/api/request-logs/summary/"
headers = {
    "Authorization": f"Bearer {YOUR_KEYWORDS_AI_API_KEY}",
    "Content-Type": "application/json"
}
params = {
    "start_time": "2025-12-01T00:00:00Z",
    "end_time": "2025-12-31T23:59:59Z"
}
data = {
    "filters": {
        "model": {
            "operator": "",
            "value": ["gpt-4o"]
        }
    }
}

response = requests.post(url, headers=headers, params=params, json=data)
print(response.json())
{
  "summary": {
    "total_cost": 15.67,
    "total_tokens": 1250000,
    "number_of_requests": 8453
  }
}

Use Cases

# Get total cost for the current month
import requests
from datetime import datetime

start_of_month = datetime.now().replace(day=1, hour=0, minute=0, second=0).isoformat() + "Z"

response = requests.get(
    "https://api.keywordsai.co/api/request-logs/summary/",
    headers={"Authorization": f"Bearer {YOUR_API_KEY}"},
    params={
        "start_time": start_of_month,
        "environment": "prod"
    }
)

summary = response.json()["summary"]
print(f"Monthly cost: ${summary['total_cost']:.2f}")
print(f"Total requests: {summary['number_of_requests']}")
# Compare costs between different models
models = ["gpt-4o", "gpt-4o-mini", "claude-3-5-sonnet-20241022"]

for model in models:
    response = requests.post(
        "https://api.keywordsai.co/api/request-logs/summary/",
        headers={"Authorization": f"Bearer {YOUR_API_KEY}"},
        json={
            "filters": {
                "model": {
                    "operator": "",
                    "value": [model]
                }
            }
        }
    )
    summary = response.json()["summary"]
    print(f"{model}: ${summary['total_cost']:.2f}")
# Get summary for a specific customer
response = requests.get(
    "https://api.keywordsai.co/api/request-logs/summary/",
    headers={"Authorization": f"Bearer {YOUR_API_KEY}"},
    params={
        "customer_identifier": "customer_123",
        "start_time": "2025-12-01T00:00:00Z"
    }
)

summary = response.json()["summary"]
print(f"Customer cost: ${summary['total_cost']:.2f}")
print(f"Customer requests: {summary['number_of_requests']}")