DEV Community

Alp Allovi
Alp Allovi

Posted on

Introducing Ayeixa FuelLite: Free-Tier Token Arbitrage & Dynamic Failover Router

Introducing Ayeixa FuelLite: Free-Tier Token Arbitrage & Dynamic Failover Router

Continuous autonomous agent execution loops consume substantial token volumes. In multi-tenant environments, unmonitored model calls quickly trigger rate limits (HTTP 429) or excessive API billing.

Ayeixa FuelLite (@ayeixa/fuellite) is an open-source TypeScript library for zero-cost multi-provider token arbitrage, quota tracking, and resilient failover.


1. Core Architecture

FuelLite provides four synchronized modules:

  1. CostEstimator: Deterministic numeric cost estimation using token counts and configured provider rates, with reported USD values rounded to six decimal places.
  2. ProviderArbitrageRouter: Ranks configured model providers, prioritizing providers configured as free-tier (isFreeTier: true) before falling back to lower-cost paid endpoints.
  3. TokenBudgetTracker: Tracks cumulative tenant and session token budgets with hard-stop limits and threshold warning alarms.
  4. FailoverExecutor: Transparently handles provider outages and rate limits with exponential backoff ($2^n \times \text{base}$) and cooldown recovery.

2. Implemented Capabilities & Test Verification

Verified with hermetic unit tests:

  • Cost Estimation: Six-decimal USD calculation across token counts (tests/cost.test.ts).
  • Arbitrage Routing: Prioritizing configured free-tier providers and lowest cost (tests/arbitrage.test.ts).
  • Budget Tracking: Hard quota enforcement and spend recording (tests/budget.test.ts).
  • Failover Logic: HTTP 429/503 retry backoff and provider hopping (tests/failover.test.ts).

Verification: 6/6 hermetic unit tests passing (0 failures).


3. Local Quick Start

git clone https://github.com/alpallovy/ayeixa-fuellite.git
cd ayeixa-fuellite
npm ci
npm run build
npm test
Enter fullscreen mode Exit fullscreen mode

Usage Example

import { CostEstimator, ProviderArbitrageRouter, TokenBudgetTracker } from './src';

const estimator = new CostEstimator();
const cost = estimator.calculateCost({
  provider: 'gemini-flash',
  inputTokens: 1500,
  outputTokens: 400,
  isFreeTier: true
});
console.log("Total Cost (USD):", cost.totalCostUsd); // 0.0

const tracker = new TokenBudgetTracker({ maxBudgetUsd: 5.0 });
tracker.recordSpend("tenant-alpha", cost.totalCostUsd, 1900);
console.log("Remaining Budget:", tracker.getRemainingBudget("tenant-alpha"));
Enter fullscreen mode Exit fullscreen mode

4. Limitations & Contributing

  • Pre-release v0.1.0-alpha. Provider rates are statically configured.
  • Public npm publication is pending.
  • Feedback and PRs welcome! See open good first issue items on GitHub.

License: MIT

Top comments (0)