# X API API reference

> The X API returns public data from X: user profiles, posts and search results. Investigators use it to look up an account by username and to search recent posts by keyword or operator such as from:. Requests go to https://api.x.com/2 with Authorization: Bearer <token>; an app-only Bearer Token is…

Source: https://osinttools.io/apis/x-api/ (Markdown view of an OSINTtools.io page; append `.md` to any page URL for this format).

Compiled by OSINTtools.io editors from the vendor's docs, updated Nov 29, 2026. Listing: https://osinttools.io/tools/x-api/

- Base URL: https://api.x.com/2
- Authentication: Bearer token in the `Authorization` header. Get a key: https://console.x.com App-only Bearer Token from the Developer Console; OAuth 2.0 user tokens also work.
- Pricing: Credits
- Rate limits: Not stated in the docs
- Vendor docs: https://docs.x.com/x-api/introduction
- OpenAPI spec: https://docs.x.com/openapi.json

## Overview

The X API returns public data from X: user profiles, posts and search results. Investigators use it to look up an account by username and to search recent posts by keyword or operator such as `from:`.

Requests go to `https://api.x.com/2` with `Authorization: Bearer <token>`; an app-only Bearer Token is created in the Developer Console. The `fields` and `expansions` parameters choose which attributes and related objects come back. The docs describe pricing as pay-per-usage with prepaid credits; per-endpoint rates and rate limits were not on the pages read. Full-archive search, filtered streams and many write endpoints also exist in the docs and are not covered here.

## Users

### Look up a user by username.

`GET /users/by/username/{username}`

- Takes: Username
- Footprint: passive (the target is not contacted)

Returns id, name and username by default; user.fields adds profile data such as public_metrics and created_at.

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `username` | path | string | yes | Letters, digits and underscores, 1 to 15 characters Example: exampleuser |
| `user.fields` | query | string | no | Comma-separated user fields to return Example: created_at,description,public_metrics,verified |
| `expansions` | query | string | no | Related objects to include Example: pinned_post_id One of: affiliation, most_recent_post_id, pinned_post_id |

Response fields:

- `data.id` (string): User ID
- `data.username` (string): Username
- `data.name` (string): Display name
- `data.description` (string): Bio (with user.fields)
- `data.created_at` (string): Account creation time (with user.fields)
- `data.public_metrics.followers_count` (integer): Followers
- `data.public_metrics.following_count` (integer): Accounts followed
- `data.public_metrics.post_count` (integer): Posts
- `errors[]` (object): Partial-failure problems

```bash
curl 'https://api.x.com/2/users/by/username/exampleuser' \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

Example response (200):

```json
{
  "data": {
    "id": "1000000000000000001",
    "username": "exampleuser",
    "name": "Example User",
    "description": "An example account.",
    "created_at": "2015-01-01T00:00:00.000Z",
    "public_metrics": {
      "followers_count": 120,
      "following_count": 80,
      "post_count": 450
    }
  }
}
```

## Search

### Posts from the last 7 days matching a search query.

`GET /tweets/search/recent`

- Takes: Username
- Footprint: passive (the target is not contacted)

At most one of start_time and since_id may be given, likewise end_time and until_id.

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `query` | query | string | yes | Search query, 1 to 4096 characters Example: from:exampleuser |
| `max_results` | query | integer | no | Results per page, 10 to 100 Example: 10 |
| `start_time` | query | string | no | Oldest time, within the last 7 days (date-time) Example: 2026-11-25T00:00:00Z |
| `end_time` | query | string | no | Newest time (date-time) Example: 2026-11-28T00:00:00Z |
| `next_token` | query | string | no | Pagination token Example: b26v89c19zqg8o3fpexample |
| `sort_order` | query | string | no | Result order Example: recency One of: recency, relevancy |
| `post.fields` | query | string | no | Comma-separated post fields Example: created_at,public_metrics,author_id |
| `expansions` | query | string | no | Related objects to include Example: author_id |

Response fields:

- `data[].id` (string): Post ID
- `data[].text` (string): Post text
- `data[].author_id` (string): Author ID (with post.fields)
- `data[].created_at` (string): Creation time (with post.fields)
- `includes.users[]` (object): Expanded users
- `meta.newest_id` (string): Newest post ID in data
- `meta.oldest_id` (string): Oldest post ID in data
- `meta.result_count` (integer): Posts in data
- `meta.next_token` (string): Token for the next page

```bash
curl 'https://api.x.com/2/tweets/search/recent?query=from%3Aexampleuser' \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

Example response (200):

```json
{
  "data": [
    {
      "id": "2000000000000000001",
      "text": "An example post.",
      "author_id": "1000000000000000001",
      "created_at": "2026-11-27T12:00:00.000Z"
    }
  ],
  "meta": {
    "newest_id": "2000000000000000001",
    "oldest_id": "2000000000000000001",
    "result_count": 1
  }
}
```

---

Listings on OSINTtools.io are reviewed by editors and re-verified on a schedule; check pricing and availability on the vendor's site before relying on them, and use OSINT tools only with a lawful basis.
Site index for agents: https://osinttools.io/llms.txt · Full catalog: https://osinttools.io/llms-full.txt · MCP server (Streamable HTTP, no auth): https://osinttools.io/mcp/
