Skip to main content

Official Python SDK for TrackYourAPI — AI API usage tracking

Project description

trackyourapi

Official Python SDK for TrackYourAPI — AI API usage tracking & observability

Track every OpenAI, Anthropic, and Gemini call automatically with 3 lines of code.

Installation

pip install trackyourapi

Quick Start

1. Get your API key

Sign in to your TrackYourAPI dashboardAPI Keys → Generate a key (qt_xxx).

2. Wrap your AI client

OpenAI

from openai import OpenAI
from trackyourapi import wrap_openai

client = wrap_openai(
    OpenAI(api_key="your_openai_key"), 
    api_key="qt_xxx",                             # your TrackYourAPI key
    endpoint="https://dbikmzkqpteicmcpfeew.supabase.co" # your TrackYourAPI endpoint
)

# ✅ All calls are now auto-tracked — no other changes needed
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

Anthropic

import anthropic
from trackyourapi import wrap_anthropic

client = wrap_anthropic(
    anthropic.Anthropic(api_key="your_anthropic_key"),
    api_key="qt_xxx",
    endpoint="https://dbikmzkqpteicmcpfeew.supabase.co"
)

message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)

What Gets Tracked

Field Description
provider openai / anthropic / google
model Exact model name (e.g. gpt-4o, claude-3-5-sonnet-20241022)
tokens Total tokens (prompt + completion)
cost USD cost calculated from official pricing tables
latency Request duration in milliseconds

Use with Standard OpenAI Environment Variables

If you already have OPENAI_API_KEY set:

import os
from openai import OpenAI
from trackyourapi import wrap_openai

client = wrap_openai(
    OpenAI(),
    api_key=os.environ.get("TRACKYOURAPI_KEY"),
    endpoint="https://dbikmzkqpteicmcpfeew.supabase.co"
)

License

MIT © TrackYourAPI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trackyourapi-0.1.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trackyourapi-0.1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file trackyourapi-0.1.0.tar.gz.

File metadata

  • Download URL: trackyourapi-0.1.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for trackyourapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2005f2e335569aa4c2a040e71372939551cf318a24db228e6243804372e4a8f3
MD5 6605ff2376087e73b4d4e98574ca3733
BLAKE2b-256 96e7658200f4beced19b933010a5a7a38cd1755422b32a8623697298ca729d13

See more details on using hashes here.

File details

Details for the file trackyourapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: trackyourapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for trackyourapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4c17101aeeb285ca82a4ab0138827c54742021fc6bdfd19b2cd8d3c609f6920
MD5 9f2e4fade0af06b2b62fdf0abbb5b8b2
BLAKE2b-256 6168f864285a9c229d7505482ee0973b86a3976e3eb5366dac00a5813d3b852f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page