X post and profile JSON, field by field: an X API v2 reference for agents

X post and profile JSON, field by field: an X API v2 reference for agents
Unif Engineering team
Unif Engineering team

Updated

X post and profile JSON from the paid UnifAPI X API and MCP, field by field in X API v2 names: posts, media, profiles, pages, billing, errors.

In short: the paid UnifAPI X API, and the call_api tool on the UnifAPI MCP server that runs the same operations, wrap every answer in one envelope (request_id, data, pagination on lists, billing) and fill data with records shaped like X API v2: XTweet for a post, XUser for a profile, XMedia and XPublicMetrics inside them, and XTrend, XCommunity and XList for the rest. Field names are snake_case, ids are strings (they exceed 2^53), created_at is X's own UTC timestamp string, counts are integers, and anything X does not report is absent rather than zero. This page lists every field with its type and the cases a program has to handle: a repost that arrives as RT @handle: … text under the account that reposted, a quote whose quoted post is not expanded, a protected account whose profile comes back but whose posts do not, impression_count that X reports on most posts but not all, and video whose playable files sit in variants.

Models are good at reading JSON they have seen. The difference between an agent that uses a data source correctly and one that guesses field names is whether the reference was in its context or in its training data. This is the reference. Every record on this page is one call away. From an agent connected to the UnifAPI MCP server, which signs in with OAuth (no key to paste) and bills pay as you go:

{ "path": "/x/users/by/username/NASA", "method": "GET" }

From code, the same operation with a workspace key:

curl -s "https://api.unifapi.com/x/users/by/username/NASA" \
  -H "Authorization: Bearer $UNIFAPI_API_KEY"

A call_api result carries the same data, pagination, billing and error fields as the HTTP body, plus the HTTP status. People who only want to look something up can use the X profile viewer and the other viewer pages, free in a browser with no login and rate-limited per visitor; their Connect button runs these same operations with your key.

If you used the old free endpoints under /tools/x/: since October 17, 2026, those URLs answer scripts and agents with HTTP 402, and the body names the MCP server and the paid operation that replaces each lookup; the viewer pages stay free in a browser. Through the MCP server at https://mcp.unifapi.com or the X API, a call bills 1 credit ($0.001) per returned record and at least 1 credit, so one post costs 1 credit. Code written against them needs the X API v2 names on this page (username, not handle; public_metrics.like_count, not metrics.likes).

Conventions

  • Ids are strings. X ids are 64-bit; JSON numbers lose precision above 2^53. Every id, author_id, conversation_id and pinned_tweet_id is a string, and so is every cursor.
  • Timestamps are X's own format, in UTC. created_at on posts and users looks like Mon Oct 05 22:33:56 +0000 2026. JavaScript's new Date() parses it; in Python use datetime.strptime(s, "%a %b %d %H:%M:%S %z %Y").
  • Counts are integers. Typed number in the spec, never formatted strings, never nulls. A count X did not report is left out, not set to 0.
  • Optional means absent. Few fields are required: id and text on a post; id, name and username on a user; type on media. Everything else is missing from the object when there is no value. Test with "impression_count" in post.public_metrics, not === 0.
  • Related records are inline. A post carries its author and media directly, so there is no separate includes object to join. expansions and the *.fields parameters are accepted, and the record has the same shape either way.
  • URLs point at X. Media URLs are on X's CDN (pbs.twimg.com, video.twimg.com) and are never re-hosted. A post has no URL field; build it as https://x.com/<username>/status/<id>.

Post: XTweet

Returned as data by /x/tweets/{id}, and as each item of data on /x/tweets?ids=… (up to 100 ids), /x/users/{id}/tweets, /x/tweets/search/recent, /x/tweets/{id}/quote_tweets, /x/users/{id}/liked_tweets, /x/lists/{id}/tweets, and the community timelines. A user timeline includes replies unless you pass exclude=replies.

FieldTypeMeaning
idstringPost ID
textstringFull text. Long posts (notes) come back in full. When media is attached, X's https://t.co/… media shortlink is still at the end; strip it before display
author_idstring, optionalThe author's user ID
created_atstring, optionalPublish time, in X's UTC format
conversation_idstring, optionalId of the root post of the thread. Equal to id on a root post; every reply in the thread carries the root's id
langstring, optionalLanguage code X detected (en, ja, …)
possibly_sensitiveboolean, optionalX's own flag
public_metricsobject, optionalSee below
attachments.media_keysarray of string, optionalPresent when media is attached; each key matches a media_key in media
edit_history_tweet_idsarray of stringThe post's versions; always at least its own id
authorXUser, optionalThe author's profile, inline
mediaarray of XMedia, optionalAbsent when the post has none

Three cases the schema does not spell out:

  • Reposts. There is no referenced_tweets field. A repost arrives as its own entry whose text starts with RT @handle: , whose author is the account that reposted, and whose original post is not expanded. Strip the prefix, read the handle after RT @ as the original author, and leave reposts out of per-post engagement averages.
  • Quotes. A quote post's text is the quoting post's own text. The quoted post is not expanded.
  • Replies. To read a thread, search conversation_id:<post id> on /x/tweets/search/recent. The results can include the root post itself; drop the item whose id equals the root id.

A post as /x/tweets/{id} returns it, trimmed:

{
  "id": "2107237881668313108",
  "text": "Time to bring them home 🌎\n\nAfter nearly eight months aboard the @Space_Station, the four members of Crew-12 will soon head back to Earth…",
  "author_id": "11348282",
  "created_at": "Mon Oct 05 22:33:56 +0000 2026",
  "lang": "en",
  "public_metrics": {
    "like_count": 7210,
    "retweet_count": 846,
    "reply_count": 262,
    "quote_count": 60,
    "bookmark_count": 197,
    "impression_count": 2823329
  },
  "attachments": { "media_keys": ["…"] },
  "edit_history_tweet_ids": ["2107237881668313108"],
  "author": {
    "id": "11348282",
    "name": "NASA",
    "username": "NASA",
    "verified": true,
    "public_metrics": { "followers_count": 92373840, … }
  },
  "media": [
    {
      "media_key": "…",
      "type": "photo",
      "url": "https://pbs.twimg.com/media/HT5pcNwXwAAKdoM.jpg",
      "width": 2048,
      "height": 1365
    }
  ]
}

public_metrics (XPublicMetrics)

One schema serves posts and users: a post carries the first six fields, a user the last four.

FieldTypeMeaning
like_countinteger, optionalLikes
retweet_countinteger, optionalReposts (retweets), not counting quotes
reply_countinteger, optionalX's reply count; can exceed the number of readable public replies
quote_countinteger, optionalQuote posts
bookmark_countinteger, optionalBookmarks
impression_countinteger, optionalViews. X reports them on most posts; absent when it does not
followers_countinteger, optionalFollowers
following_countinteger, optionalAccounts followed
tweet_countinteger, optionalLifetime post count
listed_countinteger, optionalLists the account appears on, when reported

media (XMedia)

FieldTypeMeaning
media_keystringMatches a key in the post's attachments.media_keys
typephoto | video | animated_gif
urlstring, optionalFull-size image, or the poster frame for video and GIF
preview_image_urlstring, optionalThe same image as url today
width, heightinteger, optionalOriginal dimensions
duration_msinteger, optionalVideo length
variantsarray, optionalVideo and GIF renditions on X's CDN, each { bit_rate?, content_type?, url }

On a video, url is only the poster frame. The playable files are in variants: an HLS playlist (application/x-mpegURL, no bit_rate) and several MP4 renditions (video/mp4, each with a bit_rate). To play one file, take the video/mp4 variant with the highest bit_rate:

"variants": [
  { "content_type": "application/x-mpegURL", "url": "https://video.twimg.com/amplify_video/…/pl/….m3u8" },
  { "bit_rate": 632000, "content_type": "video/mp4", "url": "https://video.twimg.com/amplify_video/…/vid/avc1/320x568/….mp4" },
  { "bit_rate": 2176000, "content_type": "video/mp4", "url": "https://video.twimg.com/amplify_video/…/vid/avc1/….mp4" }
]

With jq: [.data.media[0].variants[] | select(.content_type == "video/mp4")] | max_by(.bit_rate) | .url.

Profile: XUser

Returned as data by /x/users/by/username/{username} and /x/users/{id}, as each item of data on /x/users/by?usernames=… and /x/users?ids=… (up to 100 each), /x/users/{id}/followers, /x/users/{id}/following, /x/tweets/{id}/retweeted_by, /x/tweets/{id}/liking_users and the list and community member lists, and as author on every post.

FieldTypeMeaning
idstringUser ID. Timelines and follower lists take this, not the handle
usernamestringWithout the @, in X's casing (NASA)
namestringDisplay name
created_atstring, optionalJoin date, in X's UTC format
descriptionstring, optionalBio; absent when empty. Links in it are t.co shortlinks
locationstring, optionalFree text; absent when empty
urlstring, optionalThe website on the profile, when set. Not the x.com address, which is https://x.com/<username>
profile_image_urlstring, optionalX's 48×48 _normal rendition; replace _normal with _400x400 for a larger one
profile_banner_urlstring, optional
protectedboolean, optionalPosts are not public. The profile and its counts come back; its posts cannot be read, so check this before calling a timeline
verifiedboolean, optionalAny verification (blue, government, business)
verified_typestring, optionalBusiness, Government, … when X names one
pinned_tweet_idstring, optional
public_metricsobject, optionalfollowers_count, following_count, tweet_count, listed_count

The API does not compute an engagement rate. The one the X profile viewer shows is the average of like_count, reply_count, retweet_count and quote_count per original post on a page, divided by followers_count, as a percentage with four significant digits. Reposts are excluded from the average. For an account with 90 million followers it is a small number (0.0058), which is correct, not a bug.

Envelope and pagination

Every operation answers in the same envelope. A list looks like this:

{
  "request_id": "…",
  "data": [ … ],
  "pagination": { "has_more": true, "next_cursor": "DAAHCgABHUAq3YL__-wLAAIAAAATMj…" },
  "billing": {
    "credits_charged": 20,
    "records_charged": 20,
    "balance_remaining": 1980,
    "truncated_due_to_balance": false
  }
}
FieldTypeMeaning
request_idstringUnifAPI request id; quote it to support
dataobject or arrayOne record on single lookups (/x/tweets/{id}, /x/users/by/username/{username}, /x/communities/{id}), an array on lists
pagination.has_morebooleanTrue exactly when next_cursor is set
pagination.next_cursorstring or nullOpaque. Pass it back as pagination_token to get the next page (next_token is accepted too)
billing.credits_chargedintegerCredits this call cost
billing.records_chargedintegerRecords billed: the top-level items in data. Inline author and media do not count
billing.balance_remainingintegerWorkspace balance after the call
billing.truncated_due_to_balancebooleanTrue when the balance ran out before the page did, so data holds fewer records

pagination is on list operations only; the batch lookups (/x/tweets?ids=…, /x/users?ids=…, /x/users/by?usernames=…) return an array without it. max_results caps a page at 1 to 100 records on X list operations (max_trends, 1 to 50, on trends). A page can hold fewer than you asked for, so loop on has_more, not on a count. Cursors are opaque; some look like X's own DAAH… strings. Never parse them.

The cost is 1 credit per returned record, with a minimum of 1 credit per call, and a credit is $0.001. One post is 1 credit, a 20-post search page is 20 credits ($0.02), and a profile plus 10 posts is 11 credits. There is no subscription. The balance caps how many records a list call returns and never goes negative.

/x/trends/by/woeid/{woeid} returns data as a list of XTrend. The WOEID is Yahoo's location id: 1 is worldwide, 23424977 the United States.

FieldTypeMeaning
trend_namestringThe trend as X shows it
tweet_countinteger, optionalPost volume, present only for trends X reports one for, so treat it as optional
rankinteger, optionalPosition; when absent, use the order of data
querystring, optionalThe search X links the trend to, when given

There is no URL field; the live search on x.com is https://x.com/search?q= plus the URL-encoded query (or trend_name).

/x/communities/search?query=… returns a list of XCommunity, and /x/communities/{id} returns one: id and name, plus optional description, created_at, member_count, access and join_policy. A community's page is https://x.com/i/communities/<id>. Its posts come from /x/communities/{id}/tweets as XTweet items and its members from /x/communities/{id}/members as XUser items.

/x/lists/search?query=… returns a list of XList: id and name, plus optional description, url, member_count, follower_count and private. /x/lists/{id}/tweets and /x/lists/{id}/members return posts and users in the shapes above.

Rate-limit headers

Every HTTP response, success or error, carries the per-key quota in three spellings:

RateLimit-Policy: "api-key";q=60;w=60
RateLimit: "api-key";r=57;t=60
RateLimit-Limit: 60
RateLimit-Remaining: 57
RateLimit-Reset: 60
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 57
X-RateLimit-Reset: 60

The default is 60 requests per minute per key, counted per request, not per record. Reset is the number of seconds until the window resets, not a Unix timestamp. When the gateway turns a call away for going over, it answers 429 rate_limited with Retry-After in seconds, and the call is not charged. A call_api result carries the body and the HTTP status, not these headers.

Errors

Every non-2xx response is:

{
  "error": {
    "type": "not_found",
    "message": "X user not found: nobody_here_123",
    "request_id": "…",
    "billing": { "credits_charged": 1, … }
  }
}
typeHTTPWhen
validation_error400Missing or malformed input; issues lists each problem (a handle that is not 1–15 letters, digits or _, a max_results outside 1–100)
unauthorized401Missing or invalid API key
insufficient_credits402The balance cannot cover the call; see below
not_found404No such account or post (X Post not found: <id>). Billed the 1-credit minimum, shown in billing
rate_limited429Per-key limit reached, with Retry-After; also used when the upstream throttles
internal_error500A bug on our side
response_shape_error500X's data changed shape and the record failed the schema
upstream_error502X's data layer answered with an error
upstream_unavailable503Timed out or unreachable; retry in a few minutes

The same closed list covers every UnifAPI operation, plus invalid_id (400) for platforms whose upstream rejects an id's format. Only not_found is charged; the other errors cost nothing. Branch on type; message is for humans and can change.

An empty balance looks like this:

{
  "error": {
    "type": "insufficient_credits",
    "message": "Your workspace does not have enough credits.",
    "request_id": "…",
    "billing": { "credits_required": 1, "balance_remaining": 0 }
  }
}

The top-up link rides in the WWW-Authenticate: Payment header (link="https://api.unifapi.com/dashboard/billing", next to the price per credit). MCP clients never see headers, so call_api restates it as payment.top_up_url. Top up, then retry the same request.

Putting records into a model's context

The API and call_api answer in JSON. A 20-post page with every author inline is large, so project the fields the task needs before you hand it to a model:

curl -s -G "https://api.unifapi.com/x/tweets/search/recent" \
  --data-urlencode "query=from:NASA" -d max_results=20 \
  -H "Authorization: Bearer $UNIFAPI_API_KEY" \
  | jq -c '.data[] | {id, created_at, user: .author.username, text, likes: .public_metrics.like_count, views: .public_metrics.impression_count}'

That gives one line per post, still under the field names in this reference, so the model can ask for more by name. A full page costs 20 credits ($0.02). From an MCP client the whole result enters the model's context, so set max_results to what the task needs.

Where the schema lives

  • The spec. https://api.unifapi.com/openapi.json is the full OpenAPI document. The records on this page are its components.schemas entries XTweet, XUser, XMedia, XPublicMetrics, XTrend, XCommunity and XList, with Pagination, Billing and ErrorResponse around them.
  • From an agent. On the MCP server, list_operations finds an X operation and get_operation returns its parameters, its credit cost and a ready call_api example. Setup for Claude, ChatGPT, Cursor, Codex and other clients is on the MCP page, and the MCP docs cover the tools.
  • For people. The X / Twitter API page lists every X operation with its parameters and response fields. The viewer pages, such as the X post viewer and X search, all linked from the Twitter viewer hub, do the same lookups by hand, free in a browser.

To get a key, sign in, top up, and create a key; the Connect button on any X viewer page does all three in one flow.