debug(ai): add diagnostic logs for AI API key persistence

This commit is contained in:
Michael committed 2026-02-21 14:32:35 +01:00
1 parent c41a60b430
commit 85215565fa
2 files changed
+12 -2

No files matched your search

+4
View File
@@ -19,14 +19,18 @@ Ta réponse doit être en 1-2 phrases maximum, en français, directe et actionna
Format: "[Recommandation]: [Justification courte basée sur les données]"`;
export async function POST(req: NextRequest) {
console.log("[AI] Analysis request received.");
const config = await getSavedDatabaseConfig();
const apiKey = process.env.OPENROUTER_API_KEY || config?.openRouterKey;
const model = config?.openRouterModel || "google/gemini-flash-1.5";
if (!apiKey) {
console.error("[AI] OPENROUTER_API_KEY is missing (neither in env nor in config file).");
return NextResponse.json({ error: "OPENROUTER_API_KEY not configured. Please set it in Settings." }, { status: 503 });
}
console.log(`[AI] Using model: ${model} with API key starting with ${apiKey.substring(0, 10)}...`);
const body = await req.json();
const parsed = AnalyzeSchema.safeParse(body);
if (!parsed.success) {