import { NextRequest, NextResponse } from 'next/server'; export async function POST(request: NextRequest) { try { const body = await request.json(); const { prompt } = body; const response = await fetch('https://codestral.mistral.ai/v1/chat/completions', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ZMW8yHscLYI6iND4dh7cGuTmpO9Guotm' }, body: JSON.stringify({ model: "mistral-small", messages: [ { role: "user", content: prompt } ], temperature: 0.7, max_tokens: 400 }) }); if (!response.ok) { const errorText = await response.text(); console.error('Mistral API Error:', errorText); return NextResponse.json( { error: `API request failed: ${response.status} - ${errorText}` }, { status: response.status } ); } const data = await response.json(); return NextResponse.json(data); } catch (error) { console.error('Proxy error:', error); return NextResponse.json( { error: 'Internal server error' }, { status: 500 } ); } }