mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-22 22:48:08 +02:00
feat: add API route to fetch and format OpenRouter models with pricing data
This commit is contained in:
1 parent
a2c4a065dd
commit
d9859ff9e0
1 file changed
+16
-1
@@ -1,7 +1,22 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
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) {
|
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) {
|
if (!apiKey) {
|
||||||
return NextResponse.json({ error: "No API key provided" }, { status: 401 });
|
return NextResponse.json({ error: "No API key provided" }, { status: 401 });
|
||||||
|
|||||||
Reference in new issue
Block a user