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

@bytespell/model-provider-usage-limits

v0.0.3

Published

Fetch AI provider usage limits, pace tracking, and smart routing.

Downloads

363

Readme

@bytespell/model-provider-usage-limits

npm version

Headless library for fetching AI provider usage limits from Anthropic, GitHub Copilot, and OpenAI. Includes pace tracking and smart routing logic.

For OpenCode integration with automatic token reading, see @bytespell/opencode-usage-limits-router.

Installation

npm install @bytespell/model-provider-usage-limits

Usage

import { getUsage, pickBestProvider } from '@bytespell/model-provider-usage-limits';

// Fetch usage for one or more providers
const results = await getUsage({
  tokens: {
    anthropic: 'your-anthropic-token',
    'github-copilot': 'your-copilot-token',
    openai: 'your-openai-token',
  }
});

// results = {
//   anthropic: { provider: 'anthropic', data: { primary: { usedPercent: 88, paceDelta: 45, ... } } },
//   'github-copilot': { provider: 'github-copilot', data: { ... } },
//   openai: { provider: 'openai', data: { ... } }
// }

// Smart routing: pick best provider for a model
const best = pickBestProvider('claude-sonnet-4-5', results);
// { providerID: 'github-copilot', modelID: 'claude-sonnet-4.5', reason: 'github-copilot has most headroom (-29% behind pace)' }

Pace Tracking

The library calculates paceDelta for each usage window:

  • Positive (+X%) = Using faster than pace, will hit limits early (slow down!)
  • Negative (-X%) = Using slower than pace, quota will go unused (speed up!)

For example, if you're 79% through a 7-day window but only used 41%, paceDelta will be -38% telling you to speed up.

API Reference

getUsage(options)

Fetch usage data for providers.

interface GetUsageOptions {
  tokens: Partial<Record<ProviderID, string>>;  // Required: provider tokens
  bypassCache?: boolean;  // Force fresh fetch (default: false)
  cacheTTL?: number;      // Cache TTL in ms (default: 60000)
  timeout?: number;       // Request timeout in ms (default: 5000)
}

const results = await getUsage({ tokens: { anthropic: '...' } });
// Returns: Partial<Record<ProviderID, UsageResult>>

pickBestProvider(modelName, usageData)

Pick the best provider for a model based on current usage limits.

const best = pickBestProvider('claude-sonnet-4-5', results);
// Returns: RouterResult

listSupportedProviders()

List available provider IDs: ['anthropic', 'github-copilot', 'openai']

listRoutableModels()

List models that can be routed across providers.

Types

ProviderID

type ProviderID = 'anthropic' | 'github-copilot' | 'openai';

UsageResult

interface UsageResult {
  provider: ProviderID;
  data: UsageSnapshot | null;
  error?: ProviderUsageError;
  cache?: { age: number; timestamp: number; updatedAt: string; stale: boolean };
}

UsageSnapshot

interface UsageSnapshot {
  provider: ProviderID;
  primary: {
    usedPercent: number;
    window: string;  // e.g., "5h", "7d", "monthly"
    resetsAt: string | null;
    paceDelta: number | null;
  } | null;
  secondary: { ... } | null;
  metadata?: { plan?: string; credits?: { balance: number | null; unlimited: boolean } };
}

RouterResult

interface RouterResult {
  providerID: ProviderID;
  modelID: string;
  reason: string;
  candidates: RouterCandidate[];
}

License

MIT