feat: add API route to fetch and format OpenRouter models with pricing data

This commit is contained in:
Michael committed 2026-04-10 13:29:31 +02:00
1 parent a2c4a065dd
commit d9859ff9e0
1 file changed
+16 -1
+16 -1
View File
@@ -1,7 +1,22 @@
import { NextRequest, NextResponse } from "next/server";
import fs from "fs/promises";
import path from "path";
async function getSavedOpenRouterKey(): Promise<string | null> {
try {
const configFile = path.join(process.cwd(), "data", ".db-config.json");
const data = await fs.readFile(configFile, "utf-8");
const config = JSON.parse(data);
return config.openRouterKey ?? null;
} catch {
return null;
}
}
export async function GET(req: NextRequest) {
const apiKey = req.headers.get("x-openrouter-key") || process.env.OPENROUTER_API_KEY;
const apiKey = req.headers.get("x-openrouter-key")
|| process.env.OPENROUTER_API_KEY
|| await getSavedOpenRouterKey();
if (!apiKey) {
return NextResponse.json({ error: "No API key provided" }, { status: 401 });