How to Force a Function Call in OpenAI Realtime

have a function call in my prompt that retrieves the customer ID. I want to trigger this function at any point during a Realtime conversation without waiting for the assistant’s next turn.

I’m trying to use response.create to force the model to call this function and return the customer ID on demand. Is it possible to use the Realtime API to create an out-of-band response that executes this function and retrieves the information immediately, regardless of the conversation state?

I’ve looked at the documentation on creating responses outside the default conversation, but I’m not sure how to correctly reference previous messages or force a function call at any point.

How should I structure the response.create event and the input so that the function executes and I get the result immediately?

Hi @dsco,

I’d recommend setting the metadata when creating the OOB response. This will help you distinguish between regular responses and explicit OOB ones.

Based on the documentation, the complete context of the default/current conversation is used unless you specify a custom context via the input param, or no context by setting input to an empty list ([]).

Additionally, since you want to do this on demand, you can specify in the instructions for the OOB response to return the output as a JSON object, e.g. {"cust_id":"xxxxxxxxx"}.

Thank you for your response! I just want to clarify a few points to make sure I understand correctly.

  1. When you mention specifying metadata for out-of-band responses, could you provide a concrete example of how that would look in a response.create event? For instance, how would I structure the JSON so the model executes a function immediately and returns a structured result like {"cust_id": "xxxx"}?

  2. Regarding context, do I need to already have the function defined or initialized in the session prompt, or can I actually define and call a function on-the-fly in the middle of a conversation?

  3. My ultimate goal is to create a function that can generate a summary of the conversation without me manually providing the conversation text—essentially leveraging the real-time API to retrieve the session context itself. Is there currently any way to reference the conversation ID or its items so the model can access the conversation history for this purpose, or must all context always be passed manually in the instructions?

Any examples or guidance on these points would be extremely helpful. Thank you again for your time and clarification!