How to get the function name in realtime api for a function call?

It’s really ODD, maybe I am in a bad habit that I love reading documentation, API reference, I just couldn’t find a place to get function name of a function call so I can perform the function call?
Which server events I am supposed to look into?
I searched the internet, there’re a couple examples, but it’s obvious that the event definition in the examples are different than on OPENAI websites. I even suspect those examples are bogus, and would never work.
Who has done REALTIME API function calling? and point me to the API reference that which server event has function name to call?

1 Like

Congrats on your superpower of reading documentation, rare to find, and the basic secret to presenting expertise.

I can guide you to the documentation available…

Handling Tool Calls

The client can set default functions for the server in a session.update message, or set per-response functions in the response.create message. The server will respond with function_call items, if appropriate. The functions are passed in the format of the Chat Completions API.

When the server calls a function, it may also respond with audio and text, for example “Ok, let me submit that order for you”. The function description field is useful for guiding the server on these cases, for example “do not confirm the order is completed yet” or “respond to the user before calling the tool”.

The client must respond to the function call before by sending a conversation.item.create message with type: "function_call_output". Adding a function call output does not automatically trigger another model response, so the client may wish to trigger one immediately using response.create.

For the actual name of the tool, you will look to the .item event, now over to the API reference - and will need to expand the collapsed tiers of the object in the documentation page. Which I will do for you here.

Conversation Item Created event

API Return Object: conversation.item.created

This object is returned when a conversation item is created. Below are the parameters:


Top-Level Parameters

  • event_id

    • Type: string
    • Description: The unique ID of the server event.
  • type

    • Type: string
    • Description: The event type, must be "conversation.item.created".
  • previous_item_id

    • Type: string
    • Description: The ID of the preceding item.
  • item

    • Type: object
    • Description: The item that was created.

Item Object Parameters

  • id

    • Type: string
    • Description: The unique ID of the item.
  • object

    • Type: string
    • Description: The object type, must be "realtime.item".
  • type

    • Type: string
    • Description: The type of the item. It can be one of the following:
      • "message"
      • "function_call"
      • "function_call_output"
  • status

    • Type: string
    • Description: The status of the item. Possible values:
      • "completed"
      • "in_progress"
      • "incomplete"
  • role

    • Type: string
    • Description: The role associated with the item. Possible values:
      • "user"
      • "assistant"
      • "system"
  • content

    • Type: array
    • Description: The content of the item. It contains the following fields:

Content Object Parameters

  • type

    • Type: string
    • Description: The content type. Possible values:
      • "text"
      • "audio"
      • "input_text"
      • "input_audio"
  • text

    • Type: string
    • Description: The text content.
  • audio

    • Type: string
    • Description: Base64-encoded audio data.
  • transcript

    • Type: string
    • Description: The transcript of the audio.

Function Call Parameters (for type: "function_call")

  • call_id

    • Type: string
    • Description: The ID of the function call.
  • name

    • Type: string
    • Description: The name of the function being called.
  • arguments

    • Type: string
    • Description: The arguments of the function call.

Function Call Output Parameters (for type: "function_call_output")

  • output
    • Type: string
    • Description: The output of the function call.

You still will likely need to inspect the content of events actually being returned by the API in order to build a parser in your event collector, a bit of trial and error in text mode, before finding out if you can actually talk to the AI and coax it to use any function by changing modalities.