openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Introduce item_reference as ConversationItem in realtime types

Open SalvatoreMarragony opened this issue 11 months ago • 6 comments

Confirm this is a feature request for the Python library and not the underlying OpenAI API.

  • [x] This is a feature request for the Python library

Describe the feature or improvement you're requesting

Context

RealtimeResponseCreateParams in types.realtime has input parameter which is Optional[List[ConversationItem]]

Issue

Current types of ConversationItem don't include a class to create a conversation item of type item_reference, that can be used to reference previous messages in a realtime conversation, as described in https://platform.openai.com/docs/api-reference/realtime-client-events/response/create#realtime_client_events-response-create-response-input https://github.com/openai/openai-python/blob/f94256daf8f5d7268f28c2330dc343660a959c3e/src/openai/types/realtime/conversation_item.py#L19-L30

Proposed fix

A new class like this should work:

class RealtimeConversationItemReference(BaseModel):
    id: str
    """The unique ID of the conversation item."""

    type: Literal["item_reference"]
    """The type of the reference. Always 'item_reference`."""

To be added in the list of possible ConversationItem

Additional context

No response

SalvatoreMarragony avatar Dec 18 '25 12:12 SalvatoreMarragony

This makes sense to me. The realtime API already supports item_reference, but the Python SDK missing it in ConversationItem makes it awkward to use from typed code.

I can take a look at adding RealtimeConversationItemReference and wiring it into the ConversationItem union if that would be helpful.

CodeVishal-17 avatar Jan 04 '26 15:01 CodeVishal-17

Hi, I’d like to work on adding item_reference support to ConversationItem in the Python SDK. Before implementing, can you confirm:

expected class name (e.g. ItemReferenceConversationItem)? fields required besides type="item_reference" and item_id? whether validation helpers or tests are preferred for this change?

akshayhat avatar Jan 07 '26 18:01 akshayhat

Based on the example here https://platform.openai.com/docs/api-reference/realtime-client-events/response/create, I think just implementing this should be enough:

class RealtimeConversationItemReference(BaseModel):
    id: str
    """The unique ID of the conversation item."""

    type: Literal["item_reference"]
    """The type of the reference. Always 'item_reference`."""

SalvatoreMarragony avatar Jan 08 '26 12:01 SalvatoreMarragony

Ok,can you assign this to me?

akshayhat avatar Jan 08 '26 14:01 akshayhat

I guess this should be fixed on the OpenAPI spec itself. Created https://github.com/openai/openai-openapi/issues/514 hoping that is picked up soon.

@karpetrosyan I just noticed that you added the openapi label few weeks ago. Any idea on how long it might take to get the change in?

danigian avatar Jan 19 '26 10:01 danigian

Thanks for flagging this and helping track down the missing type. The custom-context example uses item_reference, but the shared schema omits that variant from the generated conversation-item types.

We’re closing this report to keep the work together in openai/openai-openapi#514; the fix will continue to be tracked there. Please follow that issue for the schema correction and subsequent SDK update.

marcuswood-oai avatar Sep 15 '26 18:09 marcuswood-oai