AI Cost Optimizer SDK for Developers
Track token usage • Estimate costs in real-time • Reduce AI API spend • Optimize model usage
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.
npm install toka-sdkimport { TokaClient } from 'toka-sdk';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
});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}`);Automatically tracks token usage for every request.
Know exactly how much each API call costs before and after execution.
If a request exceeds your defined budget, Toka automatically falls back to a cheaper model.
Reduce redundant API calls with:
- In-memory caching
- Optional Redis integration
Define multiple models and let Toka dynamically choose the optimal one.
Gain visibility into:
- Tokens used
- Cost per request
- Cache hits
- Fallback events
- Model selection
Toka is modular and extensible.
Use Redis for scalable, production-grade caching.
Mountable Express middleware to monitor AI usage and costs.
Interact with AI APIs directly from your terminal.
Listen to lifecycle events:
onRequestonFallbackonCacheHitonComplete
Run unit tests:
npm testBuild the project:
npm run buildLint:
npm run lintFormat:
npm run formatToka 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
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
MIT License © 2026
Abreham Wondimu Shiferaw
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 ❤️
