import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
export default async function fetchBrightDataBalance(
token: string,
): Promise<number> {
try {
const result = await fetchJSON(
"https://api.brightdata.com/customer/balance",
{
method: "GET",
bearer: token,
},
);
return result.balance - result.pending_costs;
} catch (e) {
throw new Error(`Could not fetch balance (${e}).`);
}
}