POST() — supabase Function Reference
Architecture documentation for the POST() function in route.ts from the supabase codebase.
Entity Profile
Relationship Graph
Source Code
apps/docs/app/api/ai/docs/route.ts lines 39–85
export async function POST(req: NextRequest) {
if (!openAiKey || !supabaseUrl || !supabaseServiceKey) {
return NextResponse.json(
{ error: 'Missing environment variables for AI features.' },
{ status: 500 }
)
}
const openai = new OpenAI({ apiKey: openAiKey })
const supabaseClient = new SupabaseClient(supabaseUrl, supabaseServiceKey)
try {
const { messages } = (await req.json()) as {
messages: { content: string; role: 'user' | 'assistant' }[]
}
if (!messages) {
throw new UserError('Missing messages in request data')
}
const useAltSearchIndex = !isFeatureEnabled('search:fullIndex')
const response = await clippy(openai, supabaseClient, messages, {
useAltSearchIndex,
})
// Proxy the streamed SSE response from OpenAI
return new NextResponse(response.body, {
headers: {
'Content-Type': 'text/event-stream',
},
})
} catch (error: unknown) {
console.error(error)
if (error instanceof UserError) {
return NextResponse.json({ error: error.message, data: error.data }, { status: 400 })
} else if (error instanceof ApplicationError) {
console.error(`${error.message}: ${JSON.stringify(error.data)}`)
} else {
console.error(error)
}
return NextResponse.json(
{ error: 'There was an error processing your request' },
{ status: 500 }
)
}
}
Domain
Subdomains
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free