MCPcopy Create free account
hub / github.com/admineral/OpenAI-Assistant-API-Chat / POST

Function POST

app/api/createThread/route.ts:19–51  ·  view source on GitHub ↗
(req: NextRequest)

Source from the content-addressed store, hash-verified

17});
18
19export async function POST(req: NextRequest) {
20 console.log('CREATE THREAD started');
21 if (req.method === 'POST') {
22 try {
23 const data = await req.json();
24 const inputMessage = data.inputmessage;
25
26 // Überprüfen, ob die Eingabemessage vorhanden und ein String ist
27 if (!inputMessage || typeof inputMessage !== 'string') {
28 throw new Error('inputmessage is missing or not a string');
29 }
30
31 // Thread erstellen
32 const thread = await openai.beta.threads.create({
33 messages: [
34 {
35 role: "user",
36 content: inputMessage,
37 },
38 ],
39 });
40 const threadId = thread.id;
41 console.log('Thread ID:', threadId);
42
43 return NextResponse.json({ threadId });
44 } catch (error) {
45 console.error('Error:', error);
46 return NextResponse.json({ error: (error as Error).message });
47 }
48 } else {
49 return NextResponse.json({ error: 'Method not allowed' });
50 }
51}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected