mirror of
https://github.com/bitbaum/ai-kit.git
synced 2026-12-04 11:49:15 +01:00
Three pure modules extracted from FleetCrown, where each was written after the
matching failure had already happened in production:
chain — a fallback list ACROSS VENDORS. A single pinned free model is a
scheduled outage, and stepping down to a smaller model at the
SAME vendor buys nothing: it draws on the same org-wide daily
budget, so when the day runs dry every link is already dead.
limits — the three kinds of 429 share a status, a `type` and a `code`, and
need OPPOSITE responses. Only the body separates them. Treating
`size` as `capacity` broke a tool loop on every single turn;
treating `daily` as `capacity` is the same mistake one level
deeper.
fair-share — divide a fixed daily pool across users active TODAY, paced through
the day, with a one-turn floor so nobody's first question is
refused. The goal is not throughput; it is that every active user
gets a usable amount every day.
No HTTP client on purpose. Every consumer already has its own calling
conventions, retries and logging; replacing those is a rewrite rather than an
adoption. This package supplies the decisions and leaves the fetch alone.
Two things fixed in the extraction rather than carried over:
- `humanizeWait`'s singular hour was unreachable. With the boundary at 90
minutes, anything reaching the hours branch divided to at least 1.5, which
rounds to 2 — so "about 1 hour" could never print and an hour-long wait was
announced as two. Boundary moved to 60 and the case is now tested.
- The fair-share header quoted a 10k turn cost. A measured turn was ~16k, so the
worked example understated the squeeze by nearly half.
Tests import the package BY NAME rather than reaching into dist/, so a broken
`exports` map or a `files` list that forgets to ship dist/ fails here instead of
at the first consumer's install.
31 tests, all green via `npm run verify`.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
57 lines
1.3 KiB
JSON
57 lines
1.3 KiB
JSON
{
|
|
"name": "ai-ration",
|
|
"version": "0.1.0",
|
|
"description": "Stay on free LLM tiers: a multi-vendor fallback chain, rate-limit classification that tells the three kinds of 429 apart, and fair-share rationing of a shared daily pool across users.",
|
|
"license": "MIT",
|
|
"author": "Mao Nakamoto",
|
|
"homepage": "https://github.com/maonakamoto/ai-ration#readme",
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "git+https://github.com/maonakamoto/ai-ration.git"
|
|
},
|
|
"bugs": {
|
|
"url": "https://github.com/maonakamoto/ai-ration/issues"
|
|
},
|
|
"keywords": [
|
|
"ai",
|
|
"llm",
|
|
"free-tier",
|
|
"rate-limit",
|
|
"fallback",
|
|
"quota",
|
|
"rationing",
|
|
"fair-share",
|
|
"groq",
|
|
"openrouter"
|
|
],
|
|
"type": "module",
|
|
"sideEffects": false,
|
|
"engines": {
|
|
"node": ">=18"
|
|
},
|
|
"publishConfig": {
|
|
"access": "public",
|
|
"provenance": true
|
|
},
|
|
"files": [
|
|
"dist"
|
|
],
|
|
"exports": {
|
|
".": {
|
|
"types": "./dist/index.d.ts",
|
|
"default": "./dist/index.js"
|
|
}
|
|
},
|
|
"scripts": {
|
|
"build": "tsc -p tsconfig.json",
|
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
"test": "node --test test/*.test.js",
|
|
"verify": "npm run build && npm test",
|
|
"prepare": "npm run build"
|
|
},
|
|
"devDependencies": {
|
|
"@types/node": "^22.10.2",
|
|
"typescript": "^5.8.2"
|
|
}
|
|
}
|