import { NextResponse } from 'next/server'; import { auth } from '@/auth'; import { getSystemConfig } from '@/lib/config'; import { getAnyActiveByokForUser } from '@/lib/byok'; import { resolveAiRoute } from '@/lib/ai/router'; /** * GET /api/user/ai-status * Returns the effective AI provider and model for the current user. * Used by the UI to show which model is active (BYOK vs admin). */ export async function GET() { const session = await auth(); if (!session?.user?.id) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } const config = await getSystemConfig(); const adminRoute = resolveAiRoute('chat', config); const byok = await getAnyActiveByokForUser(session.user.id, adminRoute.providerType); if (byok) { const model = (byok.model && byok.model.trim()) ? byok.model : adminRoute.modelName; return NextResponse.json({ usedByok: true, provider: byok.provider, model, source: 'byok', }); } return NextResponse.json({ usedByok: false, provider: adminRoute.providerType, model: adminRoute.modelName, source: 'admin', }); }