Skip to content
OSINTtools.io

X API API

X's official API: look up users and posts, search public posts back to 2006 and stream matches, paid per resource returned.

Base URL
https://api.x.com/2
Sign-in
Bearer token
Pricing
Credits
Format
REST
Endpoints
2

Compiled by OSINTtools.io editors from docs.x.com · updated Nov 29, 2026Work on this API? Claim it to keep these docs currentReport a mistake

Introduction

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.

Quick start

  1. Get a key

    Create an account with X API and copy your bearer token. Where to get it

  2. Make your first request

    Look up a user by username.. Replace YOUR_API_KEY and run it in a terminal, or use Try it on the endpoint.

    curl 'https://api.x.com/2/users/by/username/exampleuser' \
      -H 'Authorization: Bearer YOUR_API_KEY'
  3. Read the response

    A 200 response looks like this.

    {
      "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
        }
      }
    }

Authentication

Send your token in the Authorization header as Bearer YOUR_TOKEN.

App-only Bearer Token from the Developer Console; OAuth 2.0 user tokens also work.

Get a key from X API

Try it on this page keeps your key in your browser; it is never sent to OSINTtools.io.

Rate limits and pricing

Not stated in the docs

Pricing: credits.

Users

Look up a user by username.

GET/users/by/username/{username}

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

Path parameters

usernamestringrequiredtakes your username

Letters, digits and underscores, 1 to 15 characters

Example: exampleuser

Query parameters

user.fieldsstring

Comma-separated user fields to return

Example: created_at,description,public_metrics,verified
expansionsstring

Related objects to include

Example: pinned_post_idOne of: affiliation, most_recent_post_id, pinned_post_id
Response fields · 9Show

idstring

User ID

usernamestring

Username

namestring

Display name

descriptionstring

Bio (with user.fields)

created_atstring

Account creation time (with user.fields)

followers_countinteger

Followers

following_countinteger

Accounts followed

post_countinteger

Posts

errors[]object

Partial-failure problems

curl 'https://api.x.com/2/users/by/username/exampleuser' \
  -H 'Authorization: Bearer YOUR_API_KEY'
Replace YOUR_API_KEY with your key
Response
{
  "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
    }
  }
}

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

Query parameters

querystringrequired

Search query, 1 to 4096 characters

Example: from:exampleuser
max_resultsinteger

Results per page, 10 to 100

Example: 10Default: 10
start_timestring

Oldest time, within the last 7 days (date-time)

Example: 2026-11-25T00:00:00Z
end_timestring

Newest time (date-time)

Example: 2026-11-28T00:00:00Z
next_tokenstring

Pagination token

Example: b26v89c19zqg8o3fpexample
sort_orderstring

Result order

Example: recencyOne of: recency, relevancy
post.fieldsstring

Comma-separated post fields

Example: created_at,public_metrics,author_id
expansionsstring

Related objects to include

Example: author_id
Response fields · 9Show

idstring

Post ID

textstring

Post text

author_idstring

Author ID (with post.fields)

created_atstring

Creation time (with post.fields)

users[]object

Expanded users

newest_idstring

Newest post ID in data

oldest_idstring

Oldest post ID in data

result_countinteger

Posts in data

next_tokenstring

Token for the next page

curl 'https://api.x.com/2/tweets/search/recent?query=from%3Aexampleuser' \
  -H 'Authorization: Bearer YOUR_API_KEY'
Replace YOUR_API_KEY with your key
Response
{
  "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
  }
}