Skip to content

Toka is an AI Cost Optimizer SDK for developers to track token usage, estimate costs in real-time, reduce API spend, and optimize AI model usage. Save money, reduce redundant calls, and gain full visibility into your AI workloads.

License

Notifications You must be signed in to change notification settings

abrehamshiferaw/toka

Repository files navigation

Toka Logo

Toka SDK

AI Cost Optimizer SDK for Developers
Track token usage • Estimate costs in real-time • Reduce AI API spend • Optimize model usage

npm version    downloads/month      


🚀 What is Toka?

Toka SDK is a lightweight, developer-first AI Cost Optimization SDK built to help you:

  • Track token usage automatically
  • Estimate API costs in real-time
  • Prevent overspending with cost limits
  • Reduce redundant API calls using caching
  • Automatically fallback to cheaper AI models

It works seamlessly with modern AI models like OpenAI and other LLM providers.

If you're building AI-powered apps, Toka helps you control cost without sacrificing performance.


📦 Installation

npm install toka-sdk

⚡ Quick Start

1️⃣ Import the SDK

import { TokaClient } from 'toka-sdk';

2️⃣ Initialize the Client

const client = new TokaClient({
  apiKey: process.env.TOKA_API_KEY,
  models: ['gpt-4', 'gpt-4o-mini', 'gpt-3.5'],
  maxCostPerRequest: 0.05,   // Maximum allowed cost per request (USD)
  cache: true                // Enable built-in caching
});

3️⃣ Make an API Call with Cost Tracking

const response = await client.chat({
  messages: [
    { role: 'user', content: 'Hello world' }
  ]
});

console.log(`Text: ${response.text}`);
console.log(`Cost: $${response.cost}`);
console.log(`Tokens used: ${response.tokens}`);
console.log(`Model used: ${response.modelUsed}`);
console.log(`Cache hit: ${response.cacheHit}`);

✨ Core Features

🔍 Token Usage Tracking

Automatically tracks token usage for every request.

💰 Real-Time Cost Estimation

Know exactly how much each API call costs before and after execution.

🧠 Intelligent Cost Optimization

If a request exceeds your defined budget, Toka automatically falls back to a cheaper model.

⚡ Built-In Caching

Reduce redundant API calls with:

  • In-memory caching
  • Optional Redis integration

🔄 Multi-Model Support

Define multiple models and let Toka dynamically choose the optimal one.

📊 Logging & Analytics

Gain visibility into:

  • Tokens used
  • Cost per request
  • Cache hits
  • Fallback events
  • Model selection

🧩 Optional Enhancements

Toka is modular and extensible.

🗄 Redis Caching

Use Redis for scalable, production-grade caching.

📈 Dashboard Middleware

Mountable Express middleware to monitor AI usage and costs.

🖥 CLI Tool

Interact with AI APIs directly from your terminal.

🎣 Event Hooks

Listen to lifecycle events:

  • onRequest
  • onFallback
  • onCacheHit
  • onComplete

🧪 Testing

Run unit tests:

npm test

🛠 Development

Build the project:

npm run build

Lint:

npm run lint

Format:

npm run format

🌍 Use Cases

Toka SDK is ideal for:

  • AI SaaS platforms
  • Chatbot applications
  • AI-powered web apps
  • Prompt engineering workflows
  • High-volume AI API environments
  • Startups monitoring burn rate

🤝 Contributing

We welcome contributions from the community!

Please read CONTRIBUTING.md before submitting a pull request.

Ways to contribute:

  • Bug fixes
  • Feature improvements
  • Documentation
  • Test coverage
  • New integrations

📄 License

MIT License © 2026
Abreham Wondimu Shiferaw


⭐ Support the Project

If Toka SDK helps your project:

  • Star the repository
  • Share it with other developers
  • Open issues or feature suggestions
  • Contribute improvements

Open source grows through community support ❤️

About

Toka is an AI Cost Optimizer SDK for developers to track token usage, estimate costs in real-time, reduce API spend, and optimize AI model usage. Save money, reduce redundant calls, and gain full visibility into your AI workloads.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •