import type { ClaudeOrg, ClaudeUsageResponse } from "@/types/claude"; const BASE_URL = "https://claude.ai/api"; function cookieHeader(sessionKey: string): Record { return { Cookie: `sessionKey=${sessionKey}`, "Accept": "application/json", "Origin": "https://claude.ai", }; } export async function fetchClaudeOrgs(sessionKey: string): Promise { const response = await fetch(`${BASE_URL}/organizations`, { headers: cookieHeader(sessionKey), }); if (response.status === 401 || response.status === 403) { throw new Error("TOKEN_EXPIRED"); } if (!response.ok) { throw new Error(`HTTP_ERROR_${response.status}`); } return response.json() as Promise; } export async function fetchClaudeUsage( sessionKey: string, orgUuid: string ): Promise { const response = await fetch(`${BASE_URL}/organizations/${orgUuid}/usage`, { headers: cookieHeader(sessionKey), }); if (response.status === 401 || response.status === 403) { throw new Error("TOKEN_EXPIRED"); } if (!response.ok) { throw new Error(`HTTP_ERROR_${response.status}`); } return response.json() as Promise; }