Package Exports
- ai-meter
Readme
AI Meter is a JavaScript library designed to estimate AI models tokens and API costs. It provides a simple and efficient way to calculate token usage and associated costs for various AI models.
You can test it at AgentsTower Calculator
✨ Features
|
|
🚀 Installation
npm install ai-meter
# or
yarn add ai-meter
# or
pnpm add ai-meter📖 Quick Start
import AiMeter from 'ai-meter';
// Get tokens, costs and cost details with one request (example)
const metrics = await AiMeter.metrics('gpt-4o', 'Hello, world!', 'input');
// View response (example)
console.log(metrics);
// {
// "tokens": 4,
// "cost": 0.00001,
// "cost_details": {
// "pricing_mode": "standard",
// "cost_per_input_unit": "0.000002500000000",
// "cost_per_cached_input_unit": "0.000001250000000",
// "cost_per_output_unit": "0.000010000000000",
// "last_verified_at": "2025-06-07T05:49:08.000000Z"
// }
// }🛠 Development
Prerequisites
- Declare your script as a module (docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#applying_the_module_to_your_html)
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📝 License
This project is licensed under the ISC License - see the LICENSE file for details.
Built with ❤️ by Vista Platforms