> For the complete documentation index, see [llms.txt](https://docs.aimlapi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aimlapi.com/solutions/openai/assistants/events.md).

# Events

## Assistant stream events <a href="#assistants-streaming-events" id="assistants-streaming-events"></a>

During the execution of Runs with streaming[^1], a series of events occur sequentially, allowing you to track the current step in processing user Messages by the Assistant, as well as the statuses of the previously completed steps.

Every event in a server-sent events stream includes an `event` and `data` property:

```json5
event: thread.created
data: {"id": "thread_123", "object": "thread", ...}
```

We emit events whenever a new object is created, transitions to a new state, or is being streamed in parts (deltas). For example, we emit `thread.run.created` when a new Run is created, `thread.run.completed` when a Run completes, and so on. When an Assistant chooses to create a Message during a Run, we emit a `thread.message.created` event, a `thread.message.in_progress` event, many `thread.message.delta` events, and finally a `thread.message.completed` event.

We may add additional events over time, so we recommend handling unknown events gracefully in your code. See the [this guide](/solutions/openai/assistants.md#how-to-use-assistant-api) to learn how to integrate the Assistants API with streaming.

## Event list

<table data-full-width="false"><thead><tr><th width="238.60003662109375" valign="top">Event name</th><th width="157.199951171875" valign="top">Content of the 'data' parameter</th><th valign="top">When occurs</th></tr></thead><tbody><tr><td valign="top"><code>done</code></td><td valign="top"><code>[DONE]</code></td><td valign="top">Occurs when a stream ends.</td></tr><tr><td valign="top"><code>error</code></td><td valign="top">an error object</td><td valign="top">Occurs when an error occurs. This can happen due to an internal server error or a timeout.</td></tr><tr><td valign="top"><code>thread.created</code></td><td valign="top">a Thread object</td><td valign="top">Occurs when a new Thread is created.</td></tr><tr><td valign="top"><code>thread.message.completed</code></td><td valign="top">a Message object</td><td valign="top">Occurs when a Message is completed.</td></tr><tr><td valign="top"><code>thread.message.created</code></td><td valign="top">a Message object</td><td valign="top">Occurs when a Message is created.</td></tr><tr><td valign="top"><code>thread.message.delta</code></td><td valign="top">a Message delta</td><td valign="top">Occurs when parts of a Message are being streamed.</td></tr><tr><td valign="top"><code>thread.message.in_progress</code></td><td valign="top">a Message object</td><td valign="top">Occurs when a Message moves to an <code>in_progress</code> state.</td></tr><tr><td valign="top"><code>thread.message.incomplete</code></td><td valign="top">a Message object</td><td valign="top">Occurs when a Message ends before it is completed.</td></tr><tr><td valign="top"><code>thread.run.cancelled</code></td><td valign="top">a Run object</td><td valign="top">Occurs when a Run is cancelled.</td></tr><tr><td valign="top"><code>thread.run.cancelling</code></td><td valign="top">a Run object</td><td valign="top">Occurs when a Run moves to a <code>cancelling</code> status.</td></tr><tr><td valign="top"><code>thread.run.completed</code></td><td valign="top">a Run object</td><td valign="top">Occurs when a Run is completed.</td></tr><tr><td valign="top"><code>thread.run.created</code></td><td valign="top">a Run object</td><td valign="top">Occurs when a new Run is created.</td></tr><tr><td valign="top"><code>thread.run.expired</code></td><td valign="top">a Run object</td><td valign="top">Occurs when a Run expires.</td></tr><tr><td valign="top"><code>thread.run.failed</code></td><td valign="top">a Run object</td><td valign="top">Occurs when a Run fails.</td></tr><tr><td valign="top"><code>thread.run.in_progress</code></td><td valign="top">a Run object</td><td valign="top">Occurs when a Run moves to an <code>in_progress</code> status.</td></tr><tr><td valign="top"><code>thread.run.incomplete</code></td><td valign="top">a Run object</td><td valign="top">Occurs when a Run ends with status <code>incomplete</code>.</td></tr><tr><td valign="top"><code>thread.run.queued</code></td><td valign="top">a Run object</td><td valign="top">Occurs when a Run moves to a <code>queued</code> status.</td></tr><tr><td valign="top"><code>thread.run.requires_action</code></td><td valign="top">a Run object</td><td valign="top">Occurs when a Run moves to a <code>requires_action</code> status.</td></tr><tr><td valign="top"><code>thread.run.step.cancelled</code></td><td valign="top">a Run step object</td><td valign="top">Occurs when a Run step is cancelled.</td></tr><tr><td valign="top"><code>thread.run.step.completed</code></td><td valign="top">a Run step object</td><td valign="top">Occurs when a Run step is completed.</td></tr><tr><td valign="top"><code>thread.run.step.created</code></td><td valign="top">a Run step object</td><td valign="top">Occurs when a Run step is created.</td></tr><tr><td valign="top"><code>thread.run.step.delta</code></td><td valign="top">a Run step delta object</td><td valign="top">Occurs when parts of a Run step are being streamed.</td></tr><tr><td valign="top"><code>thread.run.step.expired</code></td><td valign="top">a Run step object</td><td valign="top">Occurs when a Run step expires.</td></tr><tr><td valign="top"><code>thread.run.step.failed</code></td><td valign="top">a Run step object</td><td valign="top">Occurs when a Run step fails.</td></tr><tr><td valign="top"><code>thread.run.step.in_progress</code></td><td valign="top">a Run step object</td><td valign="top">Occurs when a Run step moves to an <code>in_progress</code> state.</td></tr></tbody></table>

## Errors that may occur while working with Assistants

<table><thead><tr><th width="299" valign="top">Code</th><th valign="top">Overview</th></tr></thead><tbody><tr><td valign="top"><strong>401</strong> - Invalid Authentication</td><td valign="top"><strong>Cause:</strong> Invalid Authentication<br><strong>Solution:</strong> Ensure the correct AIML API key and requesting organization are being used.</td></tr><tr><td valign="top"><strong>401</strong> - Incorrect API key provided</td><td valign="top"><strong>Cause:</strong> The requesting AIML API key is not correct.<br><strong>Solution:</strong> Ensure the AIML API key used is correct, clear your browser cache, or <a href="https://aimlapi.com/app/keys/">generate a new key</a>.</td></tr><tr><td valign="top"><strong>403</strong> - Country, region, or territory not supported</td><td valign="top"><strong>Cause:</strong> You are accessing the API from an unsupported country, region, or territory.<br><strong>Solution:</strong> Please see <a href="https://platform.openai.com/docs/supported-countries">the complete list of supported countries by OpenAI</a> for more information.</td></tr><tr><td valign="top"><strong>429</strong> - Rate limit reached for requests</td><td valign="top"><strong>Cause:</strong> You are sending requests too quickly.<br><strong>Solution:</strong> Pace your requests. Read the OpenAI <a href="https://platform.openai.com/docs/guides/rate-limits">Rate limit guide</a>.</td></tr><tr><td valign="top"><strong>429</strong> - You exceeded your current quota, please check your plan and billing details</td><td valign="top"><strong>Cause:</strong> You have run out of credits or hit your maximum monthly spend.<br><strong>Solution:</strong> Buy more credits or learn how to increase your limits on <a href="https://aimlapi.com/app/billing/plans">the billing page</a> inside your personal account on the AI/ML API website.</td></tr><tr><td valign="top"><strong>500</strong> - The server had an error while processing your request</td><td valign="top"><strong>Cause:</strong> Issue on our servers.<br><strong>Solution:</strong> Retry your request after a brief wait and contact us if the issue persists.</td></tr><tr><td valign="top"><strong>503</strong> - The engine is currently overloaded, please try again later</td><td valign="top"><strong>Cause:</strong> Our servers are experiencing high traffic.<br><strong>Solution:</strong> Please retry your requests after a brief wait.</td></tr><tr><td valign="top"><strong>503</strong> - Slow Down</td><td valign="top"><strong>Cause:</strong> A sudden increase in your request rate is impacting service reliability.<br><strong>Solution:</strong> Please reduce your request rate to its original level, maintain a consistent rate for at least 15 minutes, and then gradually increase it.</td></tr></tbody></table>

[^1]: Streaming (or a **Stream mode**) refers to the continuous transmission of data or events in real-time, allowing the Assistant to process and respond to user messages step by step as they are received.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.aimlapi.com/solutions/openai/assistants/events.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
