@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
29 lines • 1.92 kB
TypeScript
/**
* The usage endpoints subscription providers publish, read into the store's window shape (senpi#3684).
* Claude answers `GET /api/oauth/usage` with `limits[]` (kind `session` / `weekly_all` / `weekly_scoped`,
* percent 0-100) or, from older servers, the `five_hour` / `seven_day[_<model>]` pair (utilization 0-100);
* ChatGPT answers `GET /backend-api/wham/usage` with `rate_limit.{primary,secondary}_window`. Window ids
* match the ones response headers and the Claude SDK report, so a poll and a turn update the same window.
*/
import type { LimitWindow } from "./limit-windows.ts";
export declare const CLAUDE_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
export declare const CODEX_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
export type UsageProvider = "anthropic-subscription" | "chatgpt-subscription";
export interface UsageReading {
readonly windows: readonly LimitWindow[];
readonly plan?: string;
}
/** A refused usage request: the status and how long the endpoint asked to be left alone. */
export declare class UsageHttpError extends Error {
readonly status: number;
readonly retryAfterMs: number | undefined;
constructor(status: number, retryAfterMs: number | undefined);
}
export type UsageFetch = (url: string, headers: Readonly<Record<string, string>>) => Promise<unknown>;
/** `redirect: "error"`: a redirecting usage endpoint is a login wall, and the bearer token must not follow it. */
export declare const fetchUsageJson: UsageFetch;
export declare function retryAfterMs(value: string | null, now: number): number | undefined;
export declare function readUsage(provider: UsageProvider, access: string, fetchJson: UsageFetch): Promise<UsageReading>;
export declare function claudeWindowsFromUsage(payload: unknown): LimitWindow[];
export declare function codexUsage(payload: unknown): UsageReading;
//# sourceMappingURL=usage-endpoints.d.ts.map