[skip ci] Initial commit — CodexBar Mobile Expo app
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import type { CodexAuth, CodexUsageResponse } from "@/types/codex";
|
||||
|
||||
const USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
|
||||
|
||||
export async function fetchCodexUsage(auth: CodexAuth): Promise<CodexUsageResponse> {
|
||||
const headers: Record<string, string> = {
|
||||
Authorization: `Bearer ${auth.accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
|
||||
if (auth.accountId) {
|
||||
headers["ChatGPT-Account-Id"] = auth.accountId;
|
||||
}
|
||||
|
||||
const response = await fetch(USAGE_URL, { headers });
|
||||
|
||||
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<CodexUsageResponse>;
|
||||
}
|
||||
Reference in New Issue
Block a user