Skip to main content
The Usage Report endpoint returns a daily breakdown of your API usage for a given time period. It aggregates data from request history, giving you visibility into token consumption, request volume, and costs.

Endpoint Information

  • URL: /v1/usage/report
  • Method: GET
  • Authentication: Required (x-api-key header or Authorization: Bearer <key>)
  • Rate Limiting: Subject to tier-based rate limits

Query Parameters

ParameterTypeRequiredDefaultDescription
periodstringNomonthPredefined time window: day (last 24 hours), week (last 7 days), or month (last 30 days)
start_datestringNoCustom range start in YYYY-MM-DD format. When both start_date and end_date are provided, they override period
end_datestringNoCustom range end in YYYY-MM-DD format. Required when start_date is set
Custom date ranges take precedence over the period parameter. If you pass both start_date/end_date and period, the custom range is used.

Code Examples

import os
import requests
from dotenv import load_dotenv

load_dotenv()

API_KEY = os.getenv("SWARMS_API_KEY")
BASE_URL = "https://api.swarms.world"

headers = {
    "x-api-key": API_KEY,
    "Content-Type": "application/json",
}

# Predefined period
response = requests.get(
    f"{BASE_URL}/v1/usage/report",
    headers=headers,
    params={"period": "week"},
)
data = response.json()

print(f"Period: {data['period']} ({data['start_date']} to {data['end_date']})")
for day in data["results"]:
    print(
        f"  {day['day']}: "
        f"cost=${day['total_cost']:.4f}, "
        f"in={day['input_tokens']:,}, "
        f"out={day['output_tokens']:,}, "
        f"reqs={day['request_count']}"
    )

# Custom date range
response = requests.get(
    f"{BASE_URL}/v1/usage/report",
    headers=headers,
    params={"start_date": "2026-03-01", "end_date": "2026-03-31"},
)

Response Schema

UsageReportOutput Object

FieldTypeDescription
resultsList[UsageReportDay]Daily usage breakdown, sorted ascending by date
periodstringThe period that was applied: day, week, month, or custom
start_datestringStart date of the report (YYYY-MM-DD)
end_datestringEnd date of the report (YYYY-MM-DD)
timestampstringISO timestamp when the report was generated

UsageReportDay Object

FieldTypeDescription
daystringDate in YYYY-MM-DD format
total_costnumberTotal cost in USD for this day
input_tokensintegerTotal input tokens consumed
output_tokensintegerTotal output tokens consumed
request_countintegerTotal number of API requests

Example Response

{
  "results": [
    {
      "day": "2026-03-28",
      "total_cost": 1.234567,
      "input_tokens": 42000,
      "output_tokens": 9800,
      "request_count": 15
    },
    {
      "day": "2026-03-29",
      "total_cost": 0.856234,
      "input_tokens": 28000,
      "output_tokens": 6200,
      "request_count": 8
    }
  ],
  "period": "week",
  "start_date": "2026-03-23",
  "end_date": "2026-03-29",
  "timestamp": "2026-03-29T18:30:00+00:00"
}

Error Responses

HTTP StatusCause
400start_date is after end_date
401Missing or invalid API key
429Rate limit exceeded
500Internal error generating the report

How Data is Aggregated

The endpoint reads from API request logs and groups entries by calendar day (UTC). For each completion log, the response usage object contributes input_tokens, output_tokens, and total_cost to that day’s totals. Every logged request increments the daily request_count. Days with zero activity are omitted from the results.