openai/openai-realtime-api-beta

Model `gpt-4o-realtime-preview-2024-10-01` should not be hardcoded

Opened this issue · 22 comments

Issue:

  • It won't allow using other models than the hardcoded model gpt-4o-realtime-preview-2024-10-01
  • A new model gpt-4o-realtime-preview-2024-12-17 has been released with lower price.
  • Alias gpt-4o-realtime-preview is also available

Expected:

  • Library consumers should be able to specify models they choose
  • The library should point model alias instead of a specific dated model
Van0SS commented

+1 this is very strange to discover and appreciate the PR!

+1 totally agree, we should have possibility to change the model.

+1 agree!

hinke commented

+1 !!

❤A new model gpt-4o-realtime-preview-2024-12-17 has been released with lower price.❤
Thank you.

please see: #92
#92 This PR introduces the ability to select a custom OpenAI realtime model in the RealtimeClient. Users can now specify the desired model for more flexibility and tailored API usage.

As a workaround, you can call client.realtime.connect directly:

export const DEFAULT_REALTIME_MODEL = "gpt-4o-realtime-preview-2024-12-17";
// ...
await client.realtime.connect({ model: DEFAULT_REALTIME_MODEL });
await client.updateSession();

The connect method in RealtimeClient is just a thin wrapper around RealtimeAPI.connect.

As a workaround, you can call client.realtime.connect directly:

export const DEFAULT_REALTIME_MODEL = "gpt-4o-realtime-preview-2024-12-17";
// ...
await client.realtime.connect({ model: DEFAULT_REALTIME_MODEL });
await client.updateSession();
The connect method in RealtimeClient is just a thin wrapper around RealtimeAPI.connect.

Do you maybe have an idea why function calling does not work when I define model like this instead of using client.connect()

I've tried the method above, even though you can see chatgpt-4o-mini-model in websocket tab, You still end up getting charged for chatgpt 4 main model on your usage history. No usage logs for 4o mini

Image

Image

Odd, it's definitely working for me! Are you using a relay?

Image

Odd, it's definitely working for me! Are you using a relay?

Image

Yup, aren't you getting charged for gpt-4o-realtime-preview instead of getting gpt-4o-mini-realtime-preview?

Odd, it's definitely working for me! Are you using a relay?
Image

Yup, aren't you getting charged for gpt-4o-realtime-preview instead of getting gpt-4o-mini-realtime-preview?

The code I suggested needs to be run on the relay server, not the client.

Yes, but it's gpt-4o-realtime-preview-2024-12-17, which is different than the hardcoded version (gpt-4o-realtime-preview-2024-10-01).

As a workaround, you can call client.realtime.connect directly:
export const DEFAULT_REALTIME_MODEL = "gpt-4o-realtime-preview-2024-12-17";
// ...
await client.realtime.connect({ model: DEFAULT_REALTIME_MODEL });
await client.updateSession();
The connect method in RealtimeClient is just a thin wrapper around RealtimeAPI.connect.

Do you maybe have an idea why function calling does not work when I define model like this instead of using client.connect()

Not sure. I use function calling in my application and noticed no difference when I swapped models. The realtime models' tool-calling abilities have seemed far more sensitive to temperature than I've expected. If you're not already, maybe try using the default value for temperature.

Quick Fix -- Go and edit the hardcoded Node file and move it to gpt-4o-realtime-preview-2024-12-17 app.js

Image

Image

I did more digging around. The relay server issue is coming from this. If you're using a relay server you definitely need the fix below
#52

Just fork the repo and add this fix and link it back to your project. That's how I did it. Check devtools of relay server

Image

It really is this easy: #89 (comment)

You just have to make those changes in the right place (i.e., where you're actually connecting to OpenAI :)

Hey guys, we are looking forward to use the latest model for realtime I do see a PR already raised so, when can we see that PR coming through to repo? PR #52

@jjmlovesgit > please see: #92 #92 This PR introduces the ability to select a custom OpenAI realtime model in the RealtimeClient. Users can now specify the desired model for more flexibility and tailored API usage.

did it actually work for you? Becuase it didnt work for me!

I hardcoded the 4o mini model here - if (!model) {
this.realtimeModel = 'gpt-4o-mini-realtime-preview-2024-12-17';
} else {
this.realtimeModel = model;
} -

BUT STILL it reverts to the default 4o model (the old one from 24/10/01) as seen on the openai dashboard.

This is a nasty bug ... I thought I used the mini, but it did not.... cost me 80$ in one day just showing demo lol... OpenAI, fix it asap, please.

@devpras22
It won't work if you are runing on the Node.js instead of Browser.
There is another hardcode in the api.js:
https://github.com/openai/openai-realtime-api-beta/blob/main/lib/api.js#L116
That's crazy.

Pr 103 lets you :)

I hope to update asap
replace hardcoded line 116 on api.js

'wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview-2024-10-01', 

to

 `wss://api.openai.com/v1/realtime?model=${model}`,

For example:

/**
       * Node.js
       */
      const moduleName = 'ws';
      const wsModule = await import(/* webpackIgnore: true */ moduleName);
      const WebSocket = wsModule.default;
      const ws = new WebSocket(
        `wss://api.openai.com/v1/realtime?model=${model}`,
        [],
        {
          finishRequest: (request) => {
            // Auth
            request.setHeader('Authorization', `Bearer ${this.apiKey}`);
            request.setHeader('OpenAI-Beta', 'realtime=v1');
            request.end();
          },
        },
      );