JSPM

ai-meter

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q30969F
  • License ISC

A javascript library designed to estimate AI models tokens and its API costs.

Package Exports

  • ai-meter

Readme

🏰 AI meter

npm version License: ISC TypeScript

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

  • 🎯 Calculate Tokens

    • Accurate token estimation for various AI models
    • Support for different tokenization methods
    • Handles both input and output tokens
  • 🔄 Cost Calculation

    • Real-time cost estimation
    • Support for multiple pricing models
    • Currency conversion support
  • 🛠 Developer Friendly

    • Free and easy-to-use API
    • Use directly with vanilla JavaScript
    • Comprehensive documentation
    • Built-in error handling
  • 📊 Extensible

    • Easy integration with existing projects
    • Add more tokenizer algorithms
    • Fork to add more functionality

🚀 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

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the ISC License - see the LICENSE file for details.


Built with ❤️ by Vista Platforms