Documentation

Get Started with TokenTra

Add AI cost tracking to your application in under 5 minutes. Our SDK wraps your existing AI clients with zero latency impact.

Quick Start Guide

Three steps to complete AI cost visibility

1

Install the SDK

npm install @tokentra/sdk
# or
pip install tokentra
2

Initialize TokenTra

import { TokenTra } from '@tokentra/sdk';

const tokentra = new TokenTra({
  apiKey: 'tt_live_xxx'
});
3

Wrap Your AI Client

import OpenAI from 'openai';

const openai = tokentra.wrap(new OpenAI());

// Use as normal - costs are tracked automatically
const response = await openai.chat.completions.create({
  model: 'gpt-4',
  messages: [{ role: 'user', content: 'Hello!' }]
}, {
  tokentra: { 
    feature: 'chat', 
    team: 'product',
    userId: 'user_123'
  }
});

That's it!

Your AI costs are now being tracked. Head to your TokenTra dashboard to see real-time spending data, set up alerts, and discover optimization opportunities.

SDK Features

Zero Latency Impact

All telemetry is sent asynchronously after the AI response is returned. Your API calls complete at exactly the same speed.

Non-Blocking

Batch telemetry collection ensures your application performance is never impacted by TokenTra.

Privacy First

We never see your prompts or responses. Only usage metrics and costs are collected.

Cost Attribution

Tag every AI request with custom attributes for granular cost tracking

// Add attribution to any request
const response = await openai.chat.completions.create({
  model: 'gpt-4',
  messages: [...]
}, {
  tokentra: {
    // Required: Feature being used
    feature: 'customer-support-chat',
    
    // Optional: Team responsible
    team: 'support-engineering',
    
    // Optional: Project or product
    project: 'helpdesk-v2',
    
    // Optional: End user (for per-user economics)
    userId: 'user_abc123',
    
    // Optional: Custom tags for your use case
    metadata: {
      environment: 'production',
      region: 'us-west',
      experimentId: 'exp_456'
    }
  }
});

Track by Team

See which teams are spending the most and enable internal chargebacks.

Track by Feature

Understand the unit economics of every AI-powered feature in your product.

Track by User

Calculate cost per user and identify heavy users driving your AI spend.

Custom Metadata

Add any custom tags for A/B tests, environments, or business-specific tracking.

Supported Providers

Works with all major AI providers out of the box

OpenAI

GPT-5, GPT-5.1, GPT-5 Pro, o3, o3-mini, DALL-E 4, Whisper v3, Embeddings

Supported

Anthropic

Claude Opus 4.5, Claude Sonnet 4, Claude Haiku 4

Supported

Google Vertex AI

Gemini 3 Pro, Gemini 3 Flash, Gemini 3 Ultra, Imagen 3

Supported

Azure OpenAI

All OpenAI models via Azure deployments (GPT-5, o3)

Supported

AWS Bedrock

Claude Opus 4.5, Titan v2, Llama 3, Mistral Large 2, Stable Diffusion 3

Supported

Python SDK

Full feature parity with the Node.js SDK

from tokentra import TokenTra
from openai import OpenAI

# Initialize TokenTra
tokentra = TokenTra(api_key='tt_live_xxx')

# Wrap your OpenAI client
openai = tokentra.wrap(OpenAI())

# Use as normal
response = openai.chat.completions.create(
    model='gpt-4',
    messages=[{'role': 'user', 'content': 'Hello!'}],
    tokentra={
        'feature': 'chat',
        'team': 'product',
        'user_id': 'user_123'
    }
)

# Async support
import asyncio
from openai import AsyncOpenAI

async_openai = tokentra.wrap(AsyncOpenAI())

async def main():
    response = await async_openai.chat.completions.create(
        model='gpt-4',
        messages=[{'role': 'user', 'content': 'Hello!'}]
    )

asyncio.run(main())

Ready to Start Tracking?

Get your API key and start tracking AI costs in under 5 minutes.