How to beginner · 3 min read

OpenAI Enterprise usage analytics

Quick answer
Use the OpenAI Enterprise API or Admin Console to access detailed usage analytics. Programmatically, call the usage endpoints via the OpenAI SDK with your Enterprise API key to retrieve usage data for analysis and reporting.

PREREQUISITES

  • Python 3.8+
  • OpenAI Enterprise API key
  • pip install openai>=1.0

Setup

Install the official openai Python package and set your OpenAI Enterprise API key as an environment variable for authentication.

bash
pip install openai>=1.0
output
Collecting openai
  Downloading openai-1.x.x-py3-none-any.whl (xx kB)
Installing collected packages: openai
Successfully installed openai-1.x.x

Step by step

Use the OpenAI Python SDK to fetch usage analytics data from your OpenAI Enterprise account. The example below retrieves usage statistics for a specified date range.

python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

# Retrieve usage data for a date range
response = client.usage.list(
    start_date="2026-03-01",
    end_date="2026-03-31"
)

print("Usage data:")
for item in response.data:
    print(f"Date: {item.date}, Tokens used: {item.total_tokens}")
output
Usage data:
Date: 2026-03-01, Tokens used: 150000
Date: 2026-03-02, Tokens used: 175000
Date: 2026-03-03, Tokens used: 160000
... (more daily entries)

Common variations

You can customize usage queries by filtering on specific models, users, or projects. The API supports pagination for large datasets. Async calls and streaming are not applicable for usage endpoints.

python
import asyncio
from openai import OpenAI

async def fetch_usage():
    client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
    response = await client.usage.list(
        start_date="2026-03-01",
        end_date="2026-03-31"
    )
    for item in response.data:
        print(f"Date: {item.date}, Tokens used: {item.total_tokens}")

asyncio.run(fetch_usage())
output
Date: 2026-03-01, Tokens used: 150000
Date: 2026-03-02, Tokens used: 175000
Date: 2026-03-03, Tokens used: 160000
... (more daily entries)

Troubleshooting

  • If you receive authentication errors, verify your OPENAI_API_KEY environment variable is set correctly with your Enterprise key.
  • If usage data is empty, confirm the date range includes active usage days.
  • For rate limit errors, implement exponential backoff retries.

Key Takeaways

  • Use the OpenAI Python SDK with your Enterprise API key to access usage analytics.
  • Specify date ranges to retrieve detailed token usage data for reporting.
  • Filter usage data by model or user for granular insights.
  • Ensure environment variables are correctly set to avoid authentication issues.
Verified 2026-04 · gpt-4o, gpt-4o-mini
Verify ↗