It was written up in 4.7 but never made the work order, which is exactly how it stayed dangerous in the first place. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
18 lines
765 B
TypeScript
18 lines
765 B
TypeScript
// POST /api/ai { "prompt": "..." } → Claude's reply.
|
|
// Set ANTHROPIC_API_KEY in your environment (e.g. a .env file) to enable this.
|
|
import { createAI } from "@wrnexus/ai";
|
|
import type { Context } from "@wrnexus/core";
|
|
|
|
const ai = createAI(); // reads ANTHROPIC_API_KEY; defaults to claude-opus-4-8
|
|
|
|
export const POST = async (ctx: Context) => {
|
|
if (!process.env.ANTHROPIC_API_KEY) {
|
|
return Response.json({ error: "Set ANTHROPIC_API_KEY to use AI." }, { status: 501 });
|
|
}
|
|
const { prompt } = await ctx.req.json().catch(() => ({}));
|
|
if (!prompt) return Response.json({ error: "Provide a 'prompt'." }, { status: 400 });
|
|
|
|
// Stream the reply back as plain text. Use `ai.generate(prompt)` for a one-shot string.
|
|
return ai.streamResponse(prompt);
|
|
};
|