ChatGPT-Next-Web/app/api/credit-summary/route.ts
2023-03-29 22:14:09 +08:00

22 lines
650 B
TypeScript

import { NextRequest } from "next/server";
export async function POST(req: NextRequest) {
try {
let apiKey = process.env.OPENAI_API_KEY;
const userApiKey = req.headers.get("token");
if (userApiKey) {
apiKey = userApiKey;
}
const res = await fetch("https://api.openai.com/dashboard/billing/credit_grants", {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
method: "GET"
});
console.log(res.body)
return new Response(res.body);
} catch (error) {
console.error("[TOKEN]", error);
}
}