Implementation:Openai Openai python Realtime Conversation Item Create
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Realtime_Communication, Conversation |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for sending conversation items and triggering responses over a Realtime WebSocket connection provided by the OpenAI Python SDK.
Description
The RealtimeConversationItemResource.create() method adds items (user messages, function call outputs) to the conversation. The RealtimeResponseResource.create() method triggers the model to generate a response based on the current conversation state. Both send typed events over the WebSocket connection.
Usage
Use connection.conversation.item.create() to add user text or function results. Use connection.response.create() to trigger generation.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/resources/beta/realtime/realtime.py
- Lines: L724-814 (sync ConversationItemResource), L976-1066 (async), L622-665 (ResponseResource)
Signature
class AsyncRealtimeConversationItemResource:
async def create(
self,
*,
item: ConversationItemParam,
event_id: str | NotGiven = NOT_GIVEN,
previous_item_id: str | NotGiven = NOT_GIVEN,
) -> None:
"""
Adds a conversation item.
Args:
item: Conversation item (message with role and content).
event_id: Optional custom event ID.
previous_item_id: Insert after this item ID.
"""
class AsyncRealtimeResponseResource:
async def create(
self,
*,
event_id: str | NotGiven = NOT_GIVEN,
response: response_create_event_param.Response | NotGiven = NOT_GIVEN,
) -> None:
"""
Triggers model response generation.
Args:
event_id: Optional custom event ID.
response: Optional response config overrides (modalities, instructions).
"""
Import
from openai import AsyncOpenAI
# Access via connection.conversation.item.create() and connection.response.create()
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| item | ConversationItemParam | Yes | Message with type, role, and content array |
| previous_item_id | str | No | Insert after this specific item |
| response | ResponseParam | No | Override modalities/instructions for this response |
Outputs
| Name | Type | Description |
|---|---|---|
| (WebSocket events) | None | Server responds with conversation.item.created, then response.created/response.done |
Usage Examples
Send Text Message and Get Response
async with client.beta.realtime.connect(model="gpt-4o-realtime-preview") as connection:
await connection.session.update(session={"modalities": ["text"]})
# Add user message
await connection.conversation.item.create(item={
"type": "message",
"role": "user",
"content": [{"type": "input_text", "text": "What is Python?"}],
})
# Trigger response
await connection.response.create()
# Receive response events
async for event in connection:
if event.type == "response.text.delta":
print(event.delta, end="", flush=True)
elif event.type == "response.done":
break
Send Function Call Output
await connection.conversation.item.create(item={
"type": "function_call_output",
"call_id": "call_abc123",
"output": '{"temperature": 22, "condition": "sunny"}',
})
await connection.response.create()
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment