Connecting to the Realtime API

Hey, has anyone successfully connected to the realtime API? Struggling to connect to it through the websocket in python. Here’s my code

import asyncio
import websockets
import json
import logging
import os

# Set up logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)


async def open_websocket_session():
    url = "wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview-2024-10-01"
    headers = {"Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}", "OpenAI-Beta": "realtime=v1"}

    try:
        async with websockets.connect(url, extra_headers=headers) as websocket:
            logger.info("Connected to server.")
            # Listen for incoming messages
            while True:
                message = await websocket.recv()
                parsed_message = json.loads(message)
                logger.info(f"Received message: {parsed_message}")

                # Process the message as needed

    except websockets.exceptions.WebSocketException as e:
        logger.error(f"WebSocket error: {e}")
    except Exception as e:
        logger.error(f"An unexpected error occurred: {e}")

2 Likes

Hey man, I have almost the same code as you and I’m not able to connect either. I’m getting 403 error. Is this what you are getting?

1 Like

Same! Might be related to the outage that’s going on right now

Someone on X is saying that open ai stated that it’s rolling out to developers starting today, meaning we might not get access today.

same here, 403 error for me too

Thanks for sharing it. I tried to connect and also got a 403.

It seems that I still don’t have the gpt-4o-audio-preview in my available list.

2 Likes

Same, 403.

Hope its not because my Openai account can see i’m in the UK.

1 Like

same here, 403 error. I even created a topic thinking I could be doing something wrong rather then being lack of authorization to the modal. With more people having the same issue, I’m less worried about doing something wrong and more inclined to think that the modal hasn’t been released yet.

1 Like

What outage?


over at status.openai.com there doesn’t seem to be one. Any source for this claim?

Same here . I guess if it doesn’t show on playground means it’s not supported yet . and also whether you’re received a notification email as usual or not !

Check you playground if Realtime API is supported or not yet

I’ve only seen one person claiming they were able to connect to it:

and I guess it has been confirmed that this is a modal access thing:

Ok, now thinking about the firefox error on the openai-realtime-console repository, the delay could be because they are not resampling the PCM data and are working on it prior to the release of the modal.

There are two ways to go about this, one of them is to resample it via the API and the other is via the client.

the API way:
This is a good approach if you need complete control over the quality of the data being fed into your model or if your clients are too diverse to reliably handle resampling on their own.

the Client way:
If you expect many clients with varying capabilities (some of which may be on devices with ample processing power, others not), this can be a way to optimize server-side resources.

f they prioritize consistency and control, do the resampling on the API side. If you want to offload work and ensure your API remains lightweight, client-side resampling would make more sense, especially if you have control over the clients and can enforce this behavior.

Personally, I’m not sure which way they are going to go about this, as the client repository wasn’t taking this into consideration. Might be after though that they realized once the openai-realtime-console and openai-realtime-api became public.

1 Like

I am able to connect to it now.

1 Like

Can you share code in case my logic is wrong?

1 Like

Is it accessible in the playground as well ?

I’m waiting for access too, middle of the night in SF right now so I fear I may be waiting a while :smiling_face_with_tear:

Trying to connect from Australia, no luck yet.

Anyone reading this, please do not enter your private API key into any third party site or platform for any reason!

The above link is from a brand new user and is almost certainly a scam to steal your money.

3 Likes

aaaand the mods got the scammer hahahah

1 Like

Please use the flag system to notify the mod team of any suspicious or inappropriate posts!

It helps a lot to keep the conversation clean and safe for everyone.

Thank you for your help!

And now, I hope access to the realtime API will be available for all of you ASAP.

4 Likes