import { fetchJson } from "../http.ts"; import { amount, label, list, numeric, object } from "../parse.ts"; import type { ProviderQuota, QuotaBucket, QuotaProvider } from "../types.ts"; /** https://api-docs.deepseek.com/api/get-user-balance; balances are decimal strings. */ export function parseDeepSeek(data: unknown): ProviderQuota { const infos = list(object(data)["balance_infos"]).map(object); const buckets: QuotaBucket[] = []; for (const info of infos) { const currency = label(info["currency"]); const value = amount( "currency", undefined, undefined, numeric(info["total_balance"]), currency, ); if (value.state !== "measured") continue; buckets.push({ id: `balance:${currency ?? buckets.length}`, label: "Balance", kind: "balance", observedAt: Date.now(), scope: infos.length > 1 ? currency : undefined, value, }); } return { provider: "deepseek", name: "DeepSeek", buckets, observedAt: Date.now(), }; } export const deepseek: QuotaProvider = { name: "DeepSeek", async fetch(key) { return parseDeepSeek( await fetchJson("https://api.deepseek.com/user/balance", { headers: { Authorization: `Bearer ${key}`, Accept: "application/json" }, }), ); }, };