This is my code next js
import { NextResponse } from 'next/server';
import OpenAI from 'openai';
export async function POST() {
if (!process.env.OPENAI_API_KEY) {
return NextResponse.json({ error: 'OPENAI_API_KEY is not set' }, { status: 500 });
}
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
try {
const workflowId = process.env.OPENAI_WORKFLOW_ID || "default";
// Create a session using the beta ChatKit API
// The previous implementation used openai.chatkit which is undefined
const session = await openai.beta.chatkit.sessions.create({
user: "user-123", // Replace with actual user ID from your auth system
workflow: { id: workflowId },
});
return NextResponse.json({ client_secret: session.client_secret });
} catch (error: any) {
console.error('Error creating ChatKit session:', error);
return NextResponse.json({ error: error.message || 'Failed to create session' }, { status: 500 });
}
}
And i got this
{“error”: “404 Workflow with id ‘wf_6xx’ not found.”}