// GET /api/offcloud/debug — diagnostic endpoint to verify API key is being read. // Returns the key detection status without exposing the key itself. // Use this to troubleshoot "stuck in mock mode" issues. import { NextResponse } from "next/server"; import { getApiKey, testConnection } from "@/lib/offcloud"; export const dynamic = "force-dynamic"; export async function GET() { const key = await getApiKey(); const keySource = process.env.OFFCLOUD_API_KEY && process.env.OFFCLOUD_API_KEY.trim() ? "env_var (HF Space Secret)" : key ? "settings_table (set via UI)" : "none"; const conn = await testConnection(); return NextResponse.json({ keyDetected: !!key, keyLength: key?.length ?? 0, keyPrefix: key ? `${key.slice(0, 4)}...${key.slice(-4)}` : null, keySource, connection: conn, timestamp: new Date().toISOString(), }); }