Every time I connect to the realtime api via websockets and send a session update, it closes the connection and returns a 1000 code.
This is my code
new WebSocket(
"wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview-2024-12-17",
{
headers: {
Authorization: `Bearer ${config.openaiApiKey}`,
"OpenAI-Beta": "realtime=v1",
},
}
);
private setupOpenAIWebSocket(): void {
this.openAIWs = new WebSocket(
"wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview-2024-12-17",
{
headers: {
Authorization: `Bearer ${config.openaiApiKey}`,
"OpenAI-Beta": "realtime=v1",
},
}
);
this.setupEventHandlers();
}
private setupEventHandlers(): void {
this.openAIWs.on("open", () => {
this.logger.info(
{
agentId: this.agent.id,
},
"Connected to OpenAI Realtime API"
);
this.sendInitialSessionUpdate();
});
this.openAIWs.on("message", (data: string) =>
this.handleOpenAIMessage(data)
);
this.openAIWs.on("close", (code: number, reason: string) => {
this.logger.info(
{
agentId: this.agent.id,
code,
reason,
},
"Disconnected from OpenAI Realtime API"
);
});
this.openAIWs.on("error", (error: Error) => {
this.logger.error(
{
error,
agentId: this.agent.id,
},
"OpenAI WebSocket error"
);
});
}
It used to work and now it worked half the time; the other half it just closes with a code=1000 after I send the session update.
I also get this error from openai after sending the session update
{
type: 'error',
event_id: 'event_AmqwXzqaPM3t6xZ7bhdHm',
error: {
type: 'server_error',
code: null,
message: 'The server had an error while processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if the error persists. (Please include the session ID sess_AmqwWcQVRKxulkoohHV2N in your message.)',
param: null,
event_id: null
}
}