Message API
Messages are individual pieces of communication within a Thread, sent either by the user or the Assistant, helping to maintain the flow and context of the conversation.
This page provides API schemas for the following methods:
https://api.apilaplas.com/threads/{threadId}/messages
https://api.apilaplas.com/threads/{threadId}/messages
https://api.apilaplas.com/threads/{threadId}/messages/{messageId}
https://api.apilaplas.com/threads/{threadId}/messages/{messageId}
https://api.apilaplas.com/threads/{threadId}/messages/{messageId}
After each API schema, you'll find a short example demonstrating how to correctly call the described method in code using the OpenAI SDK.
Note that the method names in the API schema and the SDK often differ. Accordingly, when calling these methods via the REST API, you should use the names from the API schema, while for calls through the OpenAI SDK, use the names from the examples.
API Schemas
Create a Message
Python + OpenAI SDK Example:
from openai import OpenAI
client = OpenAI()
thread_message = client.beta.threads.messages.create(
"thread_abc123",
role="user",
content="How does AI work? Explain it in simple terms.",
)
print(thread_message)
Retrieve a list of Messages from a specific Thread along with their properties
Python + OpenAI SDK Example:
from openai import OpenAI
client = OpenAI()
thread_messages = client.beta.threads.messages.list("thread_abc123")
print(thread_messages.data)
Retrieve information about a specific Message by its ID
Python + OpenAI SDK Example:
from openai import OpenAI
client = OpenAI()
message = client.beta.threads.messages.retrieve(
message_id="msg_abc123",
thread_id="thread_abc123",
)
print(message)
Modify a specific message by its ID
Python + OpenAI SDK Example:
from openai import OpenAI
client = OpenAI()
message = client.beta.threads.messages.update(
message_id="msg_abc12",
thread_id="thread_abc123",
metadata={
"modified": "true",
"user": "abc123",
},
)
print(message)
Delete a specific message by its ID
Python + OpenAI SDK Example:
from openai import OpenAI
client = OpenAI()
deleted_message = client.beta.threads.messages.delete(
message_id="msg_abc12",
thread_id="thread_abc123",
)
print(deleted_message)
Last updated