UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

46 lines (45 loc) • 2.34 kB
/** * On-Demand Account Usage Fetch * * Lightweight account-limit refresh: queries Anthropic's OAuth usage endpoint * (the same call Claude Code's /usage makes) to get fresh session / weekly / * model-scoped windows without consuming tokens or starting a 5h session. * * This complements — never replaces — the passive header capture in * accountQuota.ts: `usageToQuota` normalizes the endpoint payload into the * same `AccountQuota` shape so refreshed data flows through the existing * save/merge/cooldown chain. Manual refresh and adaptive proxy prewarming use * the same transport through the route-owned single-flight coordinator. * * Only OAuth (Bearer) accounts have subscription windows; api_key accounts * are skipped and keep their header-derived absolute limits. */ import type { AccountAllowlist, AccountQuota, AccountUsageFetchResult, AnthropicUsageResponse, ProxyPassthroughAccount } from "../types/index.js"; export declare const ANTHROPIC_USAGE_URL = "https://api.anthropic.com/api/oauth/usage"; /** * Enumerate stored Anthropic accounts for a usage refresh. * Read-only: no token refresh, no disable side effects — those decisions * belong to the caller (fetchAccountUsage / the routing path respectively). */ export declare function listAnthropicAccountsForUsage(allowlist?: AccountAllowlist): Promise<ProxyPassthroughAccount[]>; /** * Fetch fresh usage windows for one account. Return-not-throw. * Refreshes an expiring/expired token first (de-duped, rotation-safe), and * retries once through a forced refresh on a 401. */ export declare function fetchAccountUsage(account: ProxyPassthroughAccount): Promise<AccountUsageFetchResult>; /** * Normalize a usage-endpoint payload into the `AccountQuota` shape used by * the passive header path, so a refresh writes through the exact same * save/merge/cooldown chain. * * `prior` supplies fields the usage payload cannot express (fallback and * upgrade-path signals) so `isQuotaOverageAvailable` behaves identically * before and after a refresh. `unifiedStatus` is deliberately never set: * fabricating it would let the reconcile path treat a refresh like a * unified-rejected 429. */ export declare function usageToQuota(usage: AnthropicUsageResponse, opts: { now: number; prior?: AccountQuota | null; }): AccountQuota | null;