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

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_apitool on the UnifAPI MCP server that runs the same operations, wrap every answer in one envelope (request_id,data,paginationon lists,billing) and filldatawith records shaped like X API v2:XTweetfor a post,XUserfor a profile,XMediaandXPublicMetricsinside them, andXTrend,XCommunityandXListfor the rest. Field names are snake_case, ids are strings (they exceed 2^53),created_atis 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 asRT @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_countthat X reports on most posts but not all, and video whose playable files sit invariants.
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_idandpinned_tweet_idis a string, and so is every cursor. - Timestamps are X's own format, in UTC.
created_aton posts and users looks likeMon Oct 05 22:33:56 +0000 2026. JavaScript'snew Date()parses it; in Python usedatetime.strptime(s, "%a %b %d %H:%M:%S %z %Y"). - Counts are integers. Typed
numberin 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:
idandtexton a post;id,nameandusernameon a user;typeon 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
authorandmediadirectly, so there is no separateincludesobject to join.expansionsand the*.fieldsparameters 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 ashttps://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.
| Field | Type | Meaning |
|---|---|---|
id | string | Post ID |
text | string | Full 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_id | string, optional | The author's user ID |
created_at | string, optional | Publish time, in X's UTC format |
conversation_id | string, optional | Id of the root post of the thread. Equal to id on a root post; every reply in the thread carries the root's id |
lang | string, optional | Language code X detected (en, ja, …) |
possibly_sensitive | boolean, optional | X's own flag |
public_metrics | object, optional | See below |
attachments.media_keys | array of string, optional | Present when media is attached; each key matches a media_key in media |
edit_history_tweet_ids | array of string | The post's versions; always at least its own id |
author | XUser, optional | The author's profile, inline |
media | array of XMedia, optional | Absent when the post has none |
Three cases the schema does not spell out:
- Reposts. There is no
referenced_tweetsfield. A repost arrives as its own entry whosetextstarts withRT @handle:, whoseauthoris the account that reposted, and whose original post is not expanded. Strip the prefix, read the handle afterRT @as the original author, and leave reposts out of per-post engagement averages. - Quotes. A quote post's
textis 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 whoseidequals 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.
| Field | Type | Meaning |
|---|---|---|
like_count | integer, optional | Likes |
retweet_count | integer, optional | Reposts (retweets), not counting quotes |
reply_count | integer, optional | X's reply count; can exceed the number of readable public replies |
quote_count | integer, optional | Quote posts |
bookmark_count | integer, optional | Bookmarks |
impression_count | integer, optional | Views. X reports them on most posts; absent when it does not |
followers_count | integer, optional | Followers |
following_count | integer, optional | Accounts followed |
tweet_count | integer, optional | Lifetime post count |
listed_count | integer, optional | Lists the account appears on, when reported |
media (XMedia)
| Field | Type | Meaning |
|---|---|---|
media_key | string | Matches a key in the post's attachments.media_keys |
type | photo | video | animated_gif | |
url | string, optional | Full-size image, or the poster frame for video and GIF |
preview_image_url | string, optional | The same image as url today |
width, height | integer, optional | Original dimensions |
duration_ms | integer, optional | Video length |
variants | array, optional | Video 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.
| Field | Type | Meaning |
|---|---|---|
id | string | User ID. Timelines and follower lists take this, not the handle |
username | string | Without the @, in X's casing (NASA) |
name | string | Display name |
created_at | string, optional | Join date, in X's UTC format |
description | string, optional | Bio; absent when empty. Links in it are t.co shortlinks |
location | string, optional | Free text; absent when empty |
url | string, optional | The website on the profile, when set. Not the x.com address, which is https://x.com/<username> |
profile_image_url | string, optional | X's 48×48 _normal rendition; replace _normal with _400x400 for a larger one |
profile_banner_url | string, optional | |
protected | boolean, optional | Posts are not public. The profile and its counts come back; its posts cannot be read, so check this before calling a timeline |
verified | boolean, optional | Any verification (blue, government, business) |
verified_type | string, optional | Business, Government, … when X names one |
pinned_tweet_id | string, optional | |
public_metrics | object, optional | followers_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
}
}
| Field | Type | Meaning |
|---|---|---|
request_id | string | UnifAPI request id; quote it to support |
data | object or array | One record on single lookups (/x/tweets/{id}, /x/users/by/username/{username}, /x/communities/{id}), an array on lists |
pagination.has_more | boolean | True exactly when next_cursor is set |
pagination.next_cursor | string or null | Opaque. Pass it back as pagination_token to get the next page (next_token is accepted too) |
billing.credits_charged | integer | Credits this call cost |
billing.records_charged | integer | Records billed: the top-level items in data. Inline author and media do not count |
billing.balance_remaining | integer | Workspace balance after the call |
billing.truncated_due_to_balance | boolean | True 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.
Trends, communities and lists
/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.
| Field | Type | Meaning |
|---|---|---|
trend_name | string | The trend as X shows it |
tweet_count | integer, optional | Post volume, present only for trends X reports one for, so treat it as optional |
rank | integer, optional | Position; when absent, use the order of data |
query | string, optional | The 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, … }
}
}
type | HTTP | When |
|---|---|---|
validation_error | 400 | Missing or malformed input; issues lists each problem (a handle that is not 1–15 letters, digits or _, a max_results outside 1–100) |
unauthorized | 401 | Missing or invalid API key |
insufficient_credits | 402 | The balance cannot cover the call; see below |
not_found | 404 | No such account or post (X Post not found: <id>). Billed the 1-credit minimum, shown in billing |
rate_limited | 429 | Per-key limit reached, with Retry-After; also used when the upstream throttles |
internal_error | 500 | A bug on our side |
response_shape_error | 500 | X's data changed shape and the record failed the schema |
upstream_error | 502 | X's data layer answered with an error |
upstream_unavailable | 503 | Timed 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.jsonis the full OpenAPI document. The records on this page are itscomponents.schemasentriesXTweet,XUser,XMedia,XPublicMetrics,XTrend,XCommunityandXList, withPagination,BillingandErrorResponsearound them. - From an agent. On the MCP server,
list_operationsfinds an X operation andget_operationreturns its parameters, its credit cost and a readycall_apiexample. 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.