Stop paying for LLM calls you already know will fail: Budget Guard + circuit breakers in TypeScript
Описание и применение
Resili позволяет разработчикам Node.js применять политики таймаута, повторных попыток и разъёмных выключателей к асинхронным функциям, включая вызовы LLM, чтобы избежать ненужных расходов.
Задача
Node.js applications often use ad‑hoc retry, timeout, and circuit‑breaker logic that is error‑prone, hard to maintain, and can cause unnecessary LLM calls that waste money.
Результат
Resili enables developers to avoid paying for failed LLM calls by applying circuit breakers and timeouts, reducing unnecessary retries and controlling costs.
Рабочий процесс
- 1. Import resili from @resili/core.
- 2. Wrap an async function (e.g., fetch) with resili().
- 3. Chain desired policies: timeout(), retry(), circuitBreaker(), etc.
- 4. Call build() to create the resilient wrapper.
- 5. Invoke the wrapper via .call() with arguments.
- 6. For LLMs, create a provider adapter (e.g., createOpenAiProvider) and pass it to createLlmClient, then use .generate()
Доказательства
Resili is a TypeScript‑first resilience toolkit for Node.js. It wraps an async function (not a URL, not a request object) in typed policies, and it has separate packages for fetch/axios/undici and for OpenAI, Anthropic and Gemini.
Invalid options throw when the client is built, not at 3 a.m. on the first failure.
The second call fails fast with ERR_CIRCUIT_OPEN without touching the dependency.
- Дата записи: 2026-10-22T14:11:23.957Z