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

# Recent Post Counts

> This guide walks you through getting Post counts (volume) for the last 7 days. Reference for the X API v2 standard tier covering quickstart.

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>;
};

This guide walks you through getting Post counts (volume) for the last 7 days.

<Note>
  **Prerequisites**

  Before you begin, you'll need:

  * A [developer account](https://developer.x.com/en/portal/petition/essential/basic-info) with an approved App
  * Your App's Bearer Token
</Note>

***

## Get recent Post counts

<Steps>
  <Step title="Build a query">
    Use the same query syntax as recent search. For example, to count Posts from @XDevelopers:

    ```
    from:XDevelopers
    ```
  </Step>

  <Step title="Make the request">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/tweets/counts/recent?\
      query=from%3AXDevelopers&\
      granularity=day" \
        -H "Authorization: Bearer $BEARER_TOKEN"
      ```

      ```python Python SDK theme={null}
      from xdk import Client

      client = Client(bearer_token="YOUR_BEARER_TOKEN")

      # Get recent Post counts
      response = client.posts.count_recent(
          query="from:XDevelopers",
          granularity="day"
      )

      for bucket in response.data:
          print(f"{bucket.start}: {bucket.tweet_count} Posts")

      print(f"Total: {response.meta.total_tweet_count}")
      ```

      ```javascript JavaScript SDK theme={null}
      import { Client } from "@xdevplatform/xdk";

      const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

      // Get recent Post counts
      const response = await client.posts.countRecent({
        query: "from:XDevelopers",
        granularity: "day",
      });

      response.data?.forEach((bucket) => {
        console.log(`${bucket.start}: ${bucket.tweet_count} Posts`);
      });

      console.log(`Total: ${response.meta?.total_tweet_count}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="Review the response">
    ```json theme={null}
    {
      "data": [
        {
          "end": "2024-01-16T00:00:00.000Z",
          "start": "2024-01-15T00:00:00.000Z",
          "tweet_count": 5
        },
        {
          "end": "2024-01-17T00:00:00.000Z",
          "start": "2024-01-16T00:00:00.000Z",
          "tweet_count": 3
        },
        {
          "end": "2024-01-18T00:00:00.000Z",
          "start": "2024-01-17T00:00:00.000Z",
          "tweet_count": 8
        }
      ],
      "meta": {
        "total_tweet_count": 16
      }
    }
    ```
  </Step>
</Steps>

***

## Granularity options

Control how counts are grouped:

| Granularity | Description               |
| :---------- | :------------------------ |
| `minute`    | Counts per minute         |
| `hour`      | Counts per hour (default) |
| `day`       | Counts per day            |

<CodeGroup dropdown>
  ```bash cURL theme={null}
  # Get hourly counts
  curl "https://api.x.com/2/tweets/counts/recent?\
  query=python%20lang%3Aen&\
  granularity=hour" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # Get hourly counts
  response = client.posts.count_recent(
      query="python lang:en",
      granularity="hour"
  )

  for bucket in response.data:
      print(f"{bucket.start}: {bucket.tweet_count}")
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

  // Get hourly counts
  const response = await client.posts.countRecent({
    query: "python lang:en",
    granularity: "hour",
  });

  response.data?.forEach((bucket) => {
    console.log(`${bucket.start}: ${bucket.tweet_count}`);
  });
  ```
</CodeGroup>

***

## Filter by time range

Limit counts to a specific time period:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/tweets/counts/recent?\
  query=from%3AXDevelopers&\
  start_time=2024-01-10T00%3A00%3A00Z&\
  end_time=2024-01-15T00%3A00%3A00Z&\
  granularity=day" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # Get counts for a specific time range
  response = client.posts.count_recent(
      query="from:XDevelopers",
      start_time="2024-01-10T00:00:00Z",
      end_time="2024-01-15T00:00:00Z",
      granularity="day"
  )

  print(f"Total Posts: {response.meta.total_tweet_count}")
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

  // Get counts for a specific time range
  const response = await client.posts.countRecent({
    query: "from:XDevelopers",
    startTime: "2024-01-10T00:00:00Z",
    endTime: "2024-01-15T00:00:00Z",
    granularity: "day",
  });

  console.log(`Total Posts: ${response.meta?.total_tweet_count}`);
  ```
</CodeGroup>

***

## Common parameters

| Parameter     | Description                 | Default    |
| :------------ | :-------------------------- | :--------- |
| `query`       | Search query (required)     | —          |
| `granularity` | Time bucket size            | `hour`     |
| `start_time`  | Oldest timestamp (ISO 8601) | 7 days ago |
| `end_time`    | Newest timestamp (ISO 8601) | Now        |

***

## Next steps

<CardGroup cols={2}>
  <Card title="Full-archive counts" icon="vault" href="/x-api/posts/counts/quickstart/full-archive-tweet-counts">
    Get historical Post counts
  </Card>

  <Card title="Build a query" icon="magnifying-glass" href="/x-api/posts/counts/integrate/build-a-query">
    Master query syntax
  </Card>

  <Card title="API Reference" icon="code" href="/x-api/posts/get-count-of-recent-posts">
    Full endpoint documentation
  </Card>
</CardGroup>
