final-ai-fasion
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v9View latest version
// TallFit AI Backend - Correct & Secure Version export default async function handler(req) { const corsHeaders = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type', };
if (req.method === 'OPTIONS') { return new Response(null, { headers: corsHeaders }); }
try { const body = await req.json();
const response = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": Deno.env.get("ANTHROPIC_API_KEY"), // ← This line is correct
"anthropic-version": "2023-06-01"
},
body: JSON.stringify({
model: body.model || "claude-3-5-sonnet-20241022",
max_tokens: body.max_tokens || 1200,
system: body.system || "You are a helpful tall fashion assistant.",
messages: body.messages || []
})
});
const data = await response.json();
return Response.json(data, {
headers: { ...corsHeaders, "Content-Type": "application/json" }
});
} catch (error) { console.error(error); return Response.json( { error: "Failed to get response from AI" }, { status: 500, headers: corsHeaders } ); } }