Skip to main content

Overview

The usage client provides access to API usage metrics. Check your current billing period’s usage and retrieve historical usage data broken down by day. Access the usage client via client.usage.

Current

Get API usage metrics for the current billing period.
from grantex import Grantex

with Grantex(api_key="gx_live_...") as client:
    usage = client.usage.current()

    print(f"Developer: {usage.developer_id}")
    print(f"Period: {usage.period}")
    print(f"Token exchanges: {usage.token_exchanges}")
    print(f"Authorizations: {usage.authorizations}")
    print(f"Verifications: {usage.verifications}")
    print(f"Total requests: {usage.total_requests}")

UsageMetrics

FieldTypeDescription
developer_idstrThe developer organization ID.
periodstrThe current billing period (e.g., '2026-03').
token_exchangesintNumber of token exchange operations this period.
authorizationsintNumber of authorization requests this period.
verificationsintNumber of token verifications this period.
total_requestsintTotal API requests across all endpoints this period.

History

Retrieve historical usage data for the specified number of days, broken down by day.
from grantex import Grantex

with Grantex(api_key="gx_live_...") as client:
    history = client.usage.history(days=7)

    for entry in history.entries:
        print(f"{entry.date}: {entry.total_requests} requests")
        print(f"  Exchanges: {entry.token_exchanges}")
        print(f"  Authorizations: {entry.authorizations}")
        print(f"  Verifications: {entry.verifications}")

Parameters

ParameterTypeRequiredDescription
daysintYesNumber of days of history to retrieve (e.g., 7, 30, 90).

UsageHistory

FieldTypeDescription
entrieslist[UsageEntry]Daily usage entries, ordered from oldest to newest.

UsageEntry

FieldTypeDescription
datestrThe date in YYYY-MM-DD format.
token_exchangesintNumber of token exchange operations on this day.
authorizationsintNumber of authorization requests on this day.
verificationsintNumber of token verifications on this day.
total_requestsintTotal API requests on this day.

Example: Usage Dashboard

from grantex import Grantex

with Grantex(api_key="gx_live_...") as client:
    # Check current period usage
    current = client.usage.current()
    print(f"Period: {current.period}")
    print(f"Total requests: {current.total_requests}")
    print(f"  Authorizations: {current.authorizations}")
    print(f"  Token exchanges: {current.token_exchanges}")
    print(f"  Verifications: {current.verifications}")

    # Get last 30 days of usage
    history = client.usage.history(days=30)
    total_month = sum(e.total_requests for e in history.entries)
    print(f"\nLast 30 days: {total_month} total requests")

    # Find peak usage day
    peak = max(history.entries, key=lambda e: e.total_requests)
    print(f"Peak day: {peak.date} ({peak.total_requests} requests)")