# 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:

<table><thead><tr><th width="295.01666259765625"></th><th></th></tr></thead><tbody><tr><td><a href="#create-a-message">Create a Message</a></td><td><img src="https://907664505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFXiHXlmmUm0WIL4dfrh%2Fuploads%2Fgit-blob-bd94564252ef38bacd71f9b402fb7df1378a86a7%2FPOST.png?alt=media" alt="" data-size="line"> <code>https://api.apilaplas.com/threads/{threadId}/messages</code></td></tr><tr><td><a href="#retrieve-a-list-of-messages-from-a-specific-thread-along-with-their-properties">Retrieve a list of Messages from a specific Thread along with their properties</a></td><td><img src="https://907664505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFXiHXlmmUm0WIL4dfrh%2Fuploads%2Fgit-blob-b909201c46c3a87fae4151ae6b8ee708b7eaab39%2FGET.png?alt=media" alt="" data-size="line"> <code>https://api.apilaplas.com/threads/{threadId}/messages</code></td></tr><tr><td><a href="#retrieve-information-about-a-specific-message-by-its-id">Retrieve information about a specific Message by its ID</a></td><td><img src="https://907664505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFXiHXlmmUm0WIL4dfrh%2Fuploads%2Fgit-blob-b909201c46c3a87fae4151ae6b8ee708b7eaab39%2FGET.png?alt=media" alt="" data-size="line"> <code>https://api.apilaplas.com/threads/{threadId}/messages/{messageId}</code></td></tr><tr><td><a href="#modify-a-specific-message-by-its-id">Modify a specific Message by its ID</a></td><td><img src="https://907664505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFXiHXlmmUm0WIL4dfrh%2Fuploads%2Fgit-blob-bd94564252ef38bacd71f9b402fb7df1378a86a7%2FPOST.png?alt=media" alt="" data-size="line"> <code>https://api.apilaplas.com/threads/{threadId}/messages/{messageId}</code></td></tr><tr><td><a href="#delete-a-specific-message-by-its-id">Delete a specific Message by its ID</a></td><td><img src="https://907664505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFXiHXlmmUm0WIL4dfrh%2Fuploads%2Fgit-blob-392eee30190f4185190c73a3e8efce61e13aa729%2FDELETE.png?alt=media" alt="" data-size="line"> <code>https://api.apilaplas.com/threads/{threadId}/messages/{messageId}</code></td></tr></tbody></table>

After each API schema, you'll find a short example demonstrating how to correctly call the described method in code using the OpenAI SDK.

{% hint style="warning" %}
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.
{% endhint %}

## API Schemas

### Create a Message

{% openapi src="<https://api.apilaplas.com/docs-public-yaml?key=2b878a3c71a785f13366e9be96bacb29>" path="/threads/{threadId}/messages" method="post" %}
<https://api.apilaplas.com/docs-public-yaml?key=2b878a3c71a785f13366e9be96bacb29>
{% endopenapi %}

#### Python + OpenAI SDK Example:

```python
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

{% openapi src="<https://api.apilaplas.com/docs-public-yaml?key=2b878a3c71a785f13366e9be96bacb29>" path="/threads/{threadId}/messages" method="get" %}
<https://api.apilaplas.com/docs-public-yaml?key=2b878a3c71a785f13366e9be96bacb29>
{% endopenapi %}

#### Python + OpenAI SDK Example:

```python
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

{% openapi src="<https://api.apilaplas.com/docs-public-yaml?key=2b878a3c71a785f13366e9be96bacb29>" path="/threads/{threadId}/messages/{messageId}" method="get" %}
<https://api.apilaplas.com/docs-public-yaml?key=2b878a3c71a785f13366e9be96bacb29>
{% endopenapi %}

#### Python + OpenAI SDK Example:

```python
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

{% openapi src="<https://api.apilaplas.com/docs-public-yaml?key=2b878a3c71a785f13366e9be96bacb29>" path="/threads/{threadId}/messages/{messageId}" method="post" %}
<https://api.apilaplas.com/docs-public-yaml?key=2b878a3c71a785f13366e9be96bacb29>
{% endopenapi %}

#### Python + OpenAI SDK Example:

```python
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

{% openapi src="<https://api.apilaplas.com/docs-public-yaml?key=2b878a3c71a785f13366e9be96bacb29>" path="/threads/{threadId}/messages/{messageId}" method="delete" %}
<https://api.apilaplas.com/docs-public-yaml?key=2b878a3c71a785f13366e9be96bacb29>
{% endopenapi %}

#### Python + OpenAI SDK Example:

```python
from openai import OpenAI
client = OpenAI()

deleted_message = client.beta.threads.messages.delete(
  message_id="msg_abc12",
  thread_id="thread_abc123",
)
print(deleted_message)
```
