import { guardedFetch } from "./endpoint-allowlist.mjs";
import "./keychain-secrets.mjs";
//#region extensions/crypto/src/services/usage-tracker.ts
const PRICING = {
	"claude-opus-4-6": {
		inputPer1M: 15,
		outputPer1M: 75,
		cachePer1M: 1.875
	},
	"claude-sonnet-4-6": {
		inputPer1M: 3,
		outputPer1M: 15,
		cachePer1M: .375
	},
	"claude-haiku-3-5": {
		inputPer1M: .8,
		outputPer1M: 4,
		cachePer1M: .1
	},
	"gpt-4o": {
		inputPer1M: 2.5,
		outputPer1M: 10
	},
	"gpt-4o-mini": {
		inputPer1M: .15,
		outputPer1M: .6
	},
	"o3": {
		inputPer1M: 10,
		outputPer1M: 40
	}
};
const PROVIDER_DASHBOARDS = {
	anthropic: "https://console.anthropic.com/settings/billing",
	openrouter: "https://openrouter.ai/credits",
	openai: "https://platform.openai.com/usage",
	bankr: "https://bankr.bot/llm",
	"bankr-agent": "https://bankr.bot"
};
const BANKR_BASE = "https://llm.bankr.bot";
/**
* Fetch real usage data from Bankr LLM API.
* Returns null if Bankr is not configured or the call fails.
*/
async function fetchBankrUsage(days = 30) {
	const key = process.env.BANKR_LLM_KEY;
	if (!key) return null;
	try {
		const [usageRes, creditsRes] = await Promise.all([guardedFetch(`${BANKR_BASE}/v1/usage?days=${days}`, {
			headers: {
				"X-API-Key": key,
				"Content-Type": "application/json"
			},
			signal: AbortSignal.timeout(1e4)
		}), guardedFetch(`${BANKR_BASE}/v1/credits`, {
			headers: {
				"X-API-Key": key,
				"Content-Type": "application/json"
			},
			signal: AbortSignal.timeout(1e4)
		})]);
		if (!usageRes.ok) return null;
		const data = await usageRes.json();
		let credits;
		if (creditsRes.ok) {
			const creditsData = await creditsRes.json();
			credits = { balance: creditsData?.balance ?? creditsData?.credits ?? 0 };
		}
		return {
			totals: data.totals ?? {
				totalRequests: 0,
				totalInputTokens: 0,
				totalOutputTokens: 0,
				totalCacheReadInputTokens: 0,
				totalCost: 0
			},
			byModel: data.byModel ?? [],
			credits
		};
	} catch {
		return null;
	}
}
//#endregion
export { PRICING, PROVIDER_DASHBOARDS, fetchBankrUsage };

//# sourceMappingURL=usage-tracker.mjs.map