feat: add api key validation endpoint and update comic generation model

This commit is contained in:
Riccardo Giorato
2026-06-17 10:09:40 +02:00
parent 624a729b24
commit fbdf84fca7
6 changed files with 250 additions and 54 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ const FIXED_DIMENSIONS = NEW_MODEL
? { width: 896, height: 1200 }
: { width: 864, height: 1184 };
const TEXT_MODEL = "Qwen/Qwen3-Next-80B-A3B-Instruct";
const TEXT_MODEL = "Qwen/Qwen3.5-9B";
export async function POST(request: NextRequest) {
try {
+45
View File
@@ -0,0 +1,45 @@
import { type NextRequest, NextResponse } from "next/server";
import Together from "together-ai";
export async function POST(request: NextRequest) {
try {
const { apiKey } = await request.json();
if (!apiKey || typeof apiKey !== "string") {
return NextResponse.json(
{ valid: false, error: "API key is required" },
{ status: 400 },
);
}
// Dynamically fetch the fastest available model
const routerRes = await fetch("https://whichllm.together.ai/router/fast", {
next: { revalidate: 60 },
});
const { model } = await routerRes.json();
// Fire a minimal completion — 1 output token to keep cost/latency negligible
const client = new Together({ apiKey });
await client.chat.completions.create({
model,
messages: [{ role: "user", content: "hi" }],
max_tokens: 1,
});
return NextResponse.json({ valid: true });
} catch (error: unknown) {
const status =
typeof error === "object" && error !== null && "status" in error
? (error as { status: number }).status
: undefined;
if (status === 401 || status === 403) {
return NextResponse.json({ valid: false, error: "Invalid API key" });
}
return NextResponse.json(
{ valid: false, error: "Validation failed" },
{ status: 500 },
);
}
}