npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kapishdima/ai-ledger

v0.0.11

Published

AI provider balance and spending tracker for OpenCode

Readme

ai-ledger

AI provider balance and spending tracker for OpenCode

Track your AI API usage across multiple providers (OpenAI, Anthropic, Kimi, MiniMax) directly in OpenCode with automatic cost deduction and beautiful balance visualization.

Features

  • 🔍 Automatic Provider Detection - Detects configured AI providers from environment variables
  • 💰 Balance Tracking - Track spending and remaining balances in real-time
  • 📊 Visual Progress Bars - Unicode-based progress bars show usage at a glance
  • 💾 Local SQLite Storage - All data stored locally in ~/.config/opencode/ai-ledger/wallet.db
  • 🎯 Automatic Cost Deduction - Automatically deducts costs from AI requests
  • 🏦 Easy Top-ups - Simple commands to add funds to any provider

Installation

npm install ai-ledger
# or
bun add ai-ledger

Then add to your OpenCode configuration:

{
  "plugins": ["ai-ledger"]
}

Usage

Initialize

Detects configured AI providers and shows setup instructions:

/ledger_init

Example output:

Found 2 AI provider(s):

  /ledger_set openai <amount>    - Set OpenAI balance
  /ledger_set anthropic <amount>    - Set Anthropic balance

Example: /ledger_set openai 50.00

Set Initial Balance

Set the initial balance for a provider:

/ledger_set openai 50.00
/ledger_set anthropic 25.00
/ledger_set kimi 100.00

Add Funds

Add money to an existing provider balance:

/ledger_add openai 20.00

Check Balances

View all provider balances with visual progress bars:

/ledger_balance

Example output:

┌──────────────┬──────────────┬──────────┬────────────────────┐
│ Provider     │ Balance      │ Spent    │ Progress           │
├──────────────┼──────────────┼──────────┼────────────────────┤
│ OpenAI       │  $42.86      │  $7.14   │ ████░░░░░░░░░░░░░░ │
│ Anthropic    │  $25.00      │  $0.00   │ ░░░░░░░░░░░░░░░░░░░░ │
└──────────────┴──────────────┴──────────┴────────────────────┘

Automatic Tracking

Once configured, the plugin automatically tracks all AI requests and deducts costs from your balances. You'll see log messages like:

ai-ledger: openai (gpt-4): -$0.0023 | balance: $42.86

Supported Providers

The plugin automatically detects and supports:

  • OpenAI - Requires OPENAI_API_KEY
  • Anthropic - Requires ANTHROPIC_API_KEY
  • Kimi (Moonshot) - Requires MOONSHOT_API_KEY
  • MiniMax - Requires MINIMAX_API_KEY

Database

Data is stored locally in SQLite at:

~/.config/opencode/ai-ledger/wallet.db

The database contains two tables:

  • wallets - Stores provider balances and metadata
  • transactions - Stores every AI request with cost details

Requirements

  • OpenCode
  • Bun runtime (>= 1.0.0)
  • Node.js (>= 18.0.0)
  • TypeScript (>= 5.0.0)

Configuration

No additional configuration required! The plugin automatically detects your API keys from environment variables.

License

MIT

Contributing

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

Support

For issues and feature requests, please use the GitHub issue tracker.