route.ts 862 B

12345678910111213141516171819202122232425262728293031323334
  1. import { streamText } from "ai";
  2. import { buildUserPrompt, type Spec } from "@json-render/core";
  3. import { imageCatalog } from "@/lib/catalog";
  4. export const maxDuration = 60;
  5. const SYSTEM_PROMPT = imageCatalog.prompt();
  6. const DEFAULT_MODEL = "anthropic/claude-haiku-4.5";
  7. export async function POST(req: Request) {
  8. const { prompt, startingSpec } = (await req.json()) as {
  9. prompt: string;
  10. startingSpec?: Spec | null;
  11. };
  12. if (!prompt || typeof prompt !== "string") {
  13. return Response.json({ error: "prompt is required" }, { status: 400 });
  14. }
  15. const userPrompt = buildUserPrompt({
  16. prompt,
  17. currentSpec: startingSpec,
  18. });
  19. const result = streamText({
  20. model: process.env.AI_GATEWAY_MODEL ?? DEFAULT_MODEL,
  21. system: SYSTEM_PROMPT,
  22. prompt: userPrompt,
  23. temperature: 0.7,
  24. });
  25. return result.toTextStreamResponse();
  26. }