> ## Documentation Index
> Fetch the complete documentation index at: https://generaltranslation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Activity Stream

> Stream real-time account activity events

export const Button = ({href, children}) => {
  return <div className="not-prose group">
    <a href={href}>
      <button className="flex items-center space-x-2.5 py-1 px-4 bg-primary-dark dark:bg-white text-white dark:text-gray-950 rounded-full group-hover:opacity-[0.9] font-medium">
        <span>
          {children}
        </span>
        <svg width="3" height="24" viewBox="0 -9 3 24" class="h-6 rotate-0 overflow-visible"><path d="M0 0L3 3L0 6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"></path></svg>
      </button>
    </a>
  </div>;
};

The Activity Stream endpoint provides real-time delivery of account activity events for subscribed users. Receive events when users post, like, follow, receive DMs, and more.

## Overview

<CardGroup cols={2}>
  <Card title="Real-time" icon="bolt">
    Events delivered instantly
  </Card>

  <Card title="Comprehensive" icon="list">
    Posts, likes, follows, DMs, and more
  </Card>

  <Card title="Subscription-based" icon="bell">
    Subscribe to user activity
  </Card>

  <Card title="Webhook delivery" icon="webhook">
    Events delivered to your server
  </Card>
</CardGroup>

***

## Event types

| Event                   | Description                 |
| :---------------------- | :-------------------------- |
| `tweet_create_events`   | User posts a new Post       |
| `favorite_events`       | User likes a Post           |
| `follow_events`         | User follows or is followed |
| `direct_message_events` | User sends or receives a DM |
| `block_events`          | User blocks or unblocks     |
| `mute_events`           | User mutes or unmutes       |

***

## Endpoints

| Method | Endpoint                                                                           | Description                |
| :----- | :--------------------------------------------------------------------------------- | :------------------------- |
| GET    | [`/2/activity/stream`](/x-api/activity/activity-stream)                            | Connect to activity stream |
| POST   | [`/2/activity/subscriptions`](/x-api/activity/create-x-activity-subscription)      | Create a subscription      |
| GET    | [`/2/activity/subscriptions`](/x-api/activity/get-x-activity-subscriptions)        | List subscriptions         |
| PUT    | [`/2/activity/subscriptions/:id`](/x-api/activity/update-x-activity-subscription)  | Update a subscription      |
| DELETE | [`/2/activity/subscriptions/:id`](/x-api/activity/deletes-x-activity-subscription) | Delete a subscription      |

***

## How it works

1. **Create subscription** — Subscribe to a user's activity
2. **Connect to stream** — Establish persistent connection
3. **Receive events** — Get real-time activity events
4. **Process events** — Handle events in your application

***

## Example: Connect to stream

```python theme={null}
import requests

def stream_activity(bearer_token):
    url = "https://api.x.com/2/activity/stream"
    headers = {"Authorization": f"Bearer {bearer_token}"}
    
    response = requests.get(url, headers=headers, stream=True)
    
    for line in response.iter_lines():
        if line:
            print(line.decode("utf-8"))
```

***

## Getting started

<Note>
  **Prerequisites**

  * An approved [developer account](https://developer.x.com/en/portal/petition/essential/basic-info)
  * A [Project and App](/resources/fundamentals/developer-apps) in the Developer Console
  * Your App's [Bearer Token](/resources/fundamentals/authentication)
</Note>

<CardGroup cols={2}>
  <Card title="Quickstart" icon="rocket" href="/x-api/activity/quickstart">
    Set up your first subscription
  </Card>

  <Card title="Account Activity API" icon="bell" href="/x-api/account-activity/introduction">
    Webhook-based alternative
  </Card>

  <Card title="API Reference" icon="code" href="/x-api/activity/activity-stream">
    Full endpoint documentation
  </Card>
</CardGroup>
