Reference

Examples

Complete integration examples for the Tallyify API and SDK.

Overview

These examples demonstrate common use cases. All examples use the base URL https://api.tallyify.com. For local development, replace with your local URL or use the API Playground.

Models Endpoint

Fetch all models with filtering and search:

JavaScript
// List models
const res = await fetch('https://api.tallyify.com/models?search=gpt&limit=10');
const { data, pagination } = await res.json();
console.log(data, pagination.total);

The response includes a data array with pricing data (also aliased as models) and a pagination object with the total count and page info.

JSON
{
  "data": [
    {
      "id": 1,
      "name": "GPT-4o",
      "provider": "OpenAI",
      "price_input": 0.005,
      "price_output": 0.015,
      "context_window": 128000,
      "unit": "1k_tokens"
    }
  ],
  "pagination": { "page": 1, "limit": 10, "total": 247, "totalPages": 25 }
}

Compare Endpoint

Compare multiple models side by side by their IDs:

JavaScript
// Compare models by IDs
const res = await fetch('https://api.tallyify.com/compare?ids=1,2,3');
const data = await res.json();
for (const model of data) {
  console.log(model.name, model.price_input);
}

Usage Analytics

Fetch aggregated token and cost data for your account:

JavaScript
// Get usage analytics for the last 30 days
const res = await fetch('https://api.tallyify.com/profile/api-keys/usage?period=30d', {
  headers: { Authorization: 'Bearer tly_live_yourkey' }
});
const usage = await res.json();
console.log(usage.summary);
JSON
{
  "summary": {
    "monthly_spend": 18.42,
    "today_spend": 1.07,
    "monthly_tokens": 1234567,
    "top_provider_by_cost": "openai",
    "avg_latency_ms": 842,
    "error_rate": 0.4
  },
  "usage": [
    { "provider": "openai", "model_name": "gpt-4o-mini", "total_requests": 4821, "total_tokens": 890000, "total_cost": 12.30 }
  ],
  "timeseries": [
    { "date": "Mar 01", "requests": 328, "tokens": 84129, "cost": 1.42 }
  ]
}