Repository navigation
agent: copy one API endpoint (the simplest to copy) from the chat codebase to t #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { getAvailableModels } from "@/lib/ai/getAvailableModels"; | ||
|
|
||
| /** | ||
| * GET /api/ai/models | ||
| * | ||
| * Server-side endpoint that proxies `getAvailableModels()` so that the | ||
| * client can fetch model metadata without requiring server-side imports | ||
| * of `@ai-sdk/gateway`. | ||
| */ | ||
| export async function GET() { | ||
| try { | ||
| const models = await getAvailableModels(); | ||
| return Response.json({ models }); | ||
| } catch (error) { | ||
| console.error("/api/ai/models error", error); | ||
| const message = error instanceof Error ? error.message : "failed"; | ||
| return Response.json({ message }, { status: 500 }); | ||
| } | ||
| } | ||
|
|
||
| // Disable caching to always serve the latest model list. | ||
| export const dynamic = "force-dynamic"; | ||
| export const fetchCache = "force-no-store"; | ||
| export const revalidate = 0; | ||
|
Comment on lines
+10
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Require This handler is unauthenticated right now. With Line 12 making a live gateway call and Lines 21-24 disabling caching, anonymous traffic can turn this into a direct upstream fan-out path. Change the signature to accept the request and validate auth before calling 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
catchwon't handle the main failure mode.lib/ai/getAvailableModels.ts:9-16catches gateway errors and returns[], so upstream outages still produce200 { models: [] }here and never hit Line 15. Let the helper rethrow, or return a typed failure/result so this route can send a real non-200 response.🤖 Prompt for AI Agents