#can you make the realtime api start the conversation first before the user says something?
1 messages · Page 1 of 1 (latest)
Hi @sinful veldt. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, you can make the Realtime API start the conversation before the user says something. To do this, you can have the system (assistant) send the first message by creating a conversation item with the role set to "assistant" and providing the initial content. This is similar to how you would send a user message, but you set the role to "assistant" and provide the desired opening statement.
Here’s an example of how you might do this using the client event structure:
{
"type": "conversation.item.create",
"item": {
"type": "message",
"role": "assistant",
"content": [
{
"type": "input_text",
"text": "Hello! How can I help you today?"
}
]
}
}
You would send this event right after session creation, before any user input. After this, you can proceed as usual, listening for server events and handling user input.
The knowledge sources do not provide a direct, explicit example of the assistant starting the conversation, but the event structure allows you to create conversation items from either the user or the assistant, so this approach is supported by the API’s design principles for managing conversation state and items Realtime conversations guide.
If you want the model itself to generate the first message (rather than specifying it yourself), you can trigger a response from the model with an empty input or with a system prompt as the initial instruction, using the response.create event. For example, you can set up the session and then immediately send a response.create event with your desired system prompt or context Create responses with no context.
If you need more control, you can use the input array in the response.create event to provide the initial context or prompt for the model to respond to.
In summary:
- You can start the conversation by sending an assistant message as the first item.
- Alternatively, you can trigger a model response with a system prompt or empty input.
Let me know if you need a code example for a specific SDK or language!
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@sinful veldt Kapa.ai is still learning and improving, please let me know how I did by reacting below.