Message API¶
The Message API allows you to create, retrieve, update, and delete chat messages.
Overview¶
Manage chat messages and integrate with the Unique AI chat system. Includes support for streaming responses and message events.
Methods¶
unique_sdk.Message.list - Retrieve all messages
Retrieve all messages for a chat.
Parameters:
chatId(str, required) - Chat ID to retrieve messages from
Returns:
Returns a ListObject containing Message objects.
Example:
unique_sdk.Message.retrieve - Get a single message
Get a single message by ID.
Parameters:
id(str, required) - Message ID to retrievechatId(str, required) - Chat ID containing the message
Returns:
Returns a Message object.
Example:
unique_sdk.Message.create - Create a new message
Create a new message in a chat.
Parameters:
chatId(str, required) - Chat ID to create message inassistantId(str, required) - Assistant ID associated with the messagerole(Literal["ASSISTANT"], required) - Message role (must be "ASSISTANT")text(str, optional) - Message text contentreferences(List[Reference], optional) - List of source references. SeeMessage.Referencefor structure.debugInfo(Dict[str, Any], optional) - Debug information dictionarycompletedAt(datetime, optional) - Completion timestamp
Returns:
Returns a Message object.
Example:
unique_sdk.Message.create_event - Create a message event
Compatibility
Compatible with release >.42
Create a message event to update the chat UI without database persistence. Useful for custom streaming.
Warning
This only updates the UI, not the database.
Parameters:
messageId(str, required) - Message ID to updatechatId(str, required) - Chat ID containing the messagetext(str, optional) - Updated message textoriginalText(str, optional) - Original message textreferences(List[Reference], optional) - List of source references. SeeMessage.Referencefor structure.gptRequest(Dict[str, Any], optional) - GPT request datadebugInfo(Dict[str, Any], optional) - Debug information dictionarycompletedAt(datetime, optional) - Completion timestamp
Returns:
Returns a Message object.
Example:
unique_sdk.Message.modify - Update an existing message
Update an existing message.
Tip
Only modify debugInfo on user messages - it's only displayed there in the frontend.
Parameters:
id(str, required) - Message ID to updatechatId(str, required) - Chat ID containing the messagetext(str, optional) - Updated message textreferences(List[Reference], optional) - List of source references. SeeMessage.Referencefor structure.debugInfo(Dict[str, Any], optional) - Debug information dictionarycompletedAt(datetime, optional) - Completion timestamp
Returns:
Returns a Message object.
Example:
unique_sdk.Message.delete - Delete a message
Delete a message from a chat.
Warning
Message deletion doesn't auto-sync with UI. Users must refresh to see changes.
Parameters:
message_id(str, required) - Message ID to delete (positional argument)chatId(str, required) - Chat ID containing the message
Returns:
Returns a Message object.
Example:
Streaming Methods¶
unique_sdk.Integrated.chat_stream_completion - Stream AI response (using ChatCompletions API)
Stream an AI-generated response to the chat frontend with automatic source reference handling, using ChatCompletions API.
Source References: [source0] in the stream is automatically converted to <sup>1</sup> with proper reference linking.
unique_sdk.Integrated.responses_stream - Stream AI response (using Responses API)
Stream an AI-generated response to the chat frontend with automatic source reference handling, using Responses API.
Input Types¶
Message.Reference¶
The Message.Reference type defines source reference information for messages
Fields:
name(str, required) - Reference name/titledescription(str, optional) - Reference descriptionurl(str, optional) - Reference URLsequenceNumber(int, required) - Sequence number for ordering referencesoriginalIndex(list[int], optional) - Original index positionssourceId(str, required) - Source identifiersource(str, required) - Source name/path
Used in: Message.create(), Message.modify(), Message.create_event()
Return Types¶
Message¶
The Message object represents a chat message
Fields:
id(str) - Unique message identifierchatId(str) - Chat ID containing the messagetext(str | None) - Message text contentrole(Literal["SYSTEM", "USER", "ASSISTANT"]) - Message rolegptRequest(Dict[str, Any] | None) - GPT request datadebugInfo(Dict[str, Any] | None) - Debug information dictionaryreferences(List[Reference] | None) - List of source referencescompletedAt(datetime | None) - Completion timestampcreatedAt(str | None) - Creation timestamp (ISO 8601)updatedAt(str | None) - Last update timestamp (ISO 8601)
Returned by: Message.list(), Message.retrieve(), Message.create(), Message.modify(), Message.delete(), Message.create_event()
ListObject¶
The ListObject type represents a paginated list of messages
Fields:
data(List[Message]) - List of message objectshas_more(bool) - Whether there are more items to retrieveobject(str) - Object type identifier (always "list")
Returned by: Message.list()
Related Resources¶
- Message Log API - Track message execution steps
- Message Execution API - Manage long-running message operations
- Message Assessment API - Evaluate message quality
- Chat History Utility - Manage conversation history