Tutorials

OpenAI Cost Tracking: How to Build a Dashboard or Use Usagely

OpenAI Cost Tracking: How to Build a Dashboard or Use Usagely
Usagely Team

Usagely Team

April 19, 2026

5 min read

The OpenAI Billing Problem

OpenAI provides a usage page, but it has limitations:

  • Only shows aggregate spending, not per-user or per-project
  • No real-time alerts when spending spikes
  • No comparison to other AI providers in one view
  • Limited historical data and no trend analysis
  • No way to set budgets or anomaly thresholds

Option 1: Build a Basic Tracker

Here's a minimal approach to track OpenAI costs:

import openai
import time
from datetime import datetime

costs = {
    "gpt-4o": {"input": 2.50, "output": 10.00},      # per 1M tokens
    "gpt-4o-mini": {"input": 0.15, "output": 0.60},   # per 1M tokens
    "o1": {"input": 15.00, "output": 60.00},           # per 1M tokens
}

def track_call(model, input_tokens, output_tokens):
    input_cost = (input_tokens / 1_000_000) * costs[model]["input"]
    output_cost = (output_tokens / 1_000_000) * costs[model]["output"]
    return input_cost + output_cost

This works for basic tracking, but you'll quickly run into issues:

  • Manual instrumentation required for every API call
  • No multi-provider view (what about Anthropic? Bedrock?)
  • No team/user attribution — who made which call?
  • No alerting — you only see costs after the fact
  • No historical trends — is spending going up or down?

Option 2: Use the OpenAI API Usage Endpoint

OpenAI's /v1/organization/usage endpoint provides programmatic access to spending data. You can poll it daily:

curl https://api.openai.com/v1/organization/usage \
  -H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
  -d '{"start_time": 1710720000, "end_time": 1710806400}'

But this only covers OpenAI. If your team also uses Anthropic, AWS Bedrock, or GitHub Copilot, you'd need separate integrations for each.

Option 3: Use Usagely (Recommended)

Usagely handles OpenAI cost tracking (and every other provider) out of the box:

  1. Connect your API key — Usagely securely reads your usage data
  2. See costs in minutes — Per-model, per-user, per-project breakdown
  3. Set budgets — Get alerts at thresholds you define
  4. Detect anomalies — Automatic spike detection
  5. Compare providers — OpenAI vs. Anthropic vs. Bedrock in one view

Setup in Under 5 Minutes

git clone https://github.com/usagely/usagely
cd usagely
cp .env.example .env
# Add your OpenAI API key to the config
make dev

Open http://localhost:3000 and you'll see your AI spending dashboard with seed data. Plug in your real API keys and watch your actual costs populate.

Beyond OpenAI: Multi-Provider Cost Tracking

The real power of a unified dashboard is comparing costs across providers:

  • Is GPT-4o or Claude Sonnet cheaper for your use case?
  • Which team uses the most AI resources?
  • Are you paying for duplicate tools?
  • Should you switch from OpenAI to Bedrock for cost reasons?

These questions are impossible to answer with a single-provider dashboard. Usagely gives you the full picture.

Get started for free — Usagely is open source under AGPL-3.0. Self-host it in minutes.