Files
Momento/memento-note/app/api/user/ai-status/route.ts
Antigravity a623454347
Some checks failed
CI / Lint, Unit Tests & Build (push) Failing after 1m32s
CI / Deploy production (on server) (push) Has been skipped
perf: memo GridCard, fuse save fns, fix slash tab active color
2026-06-14 14:06:05 +00:00

40 lines
1.1 KiB
TypeScript

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',
});
}