Every object in the X API—posts, users, lists, DMs, spaces—has a unique ID. Understanding how these IDs work helps you build reliable integrations.
X IDs are 64-bit unsigned integers generated using a system called “Snowflake.” Each ID encodes:
- Timestamp — When the object was created
- Worker number — Which server generated the ID
- Sequence number — Order within that millisecond
This means IDs are roughly time-ordered: higher IDs generally represent newer objects.
IDs are globally unique across all of X, not just within a single object type.
String vs. integer representation
Always use string IDs in your code. Some programming languages (like JavaScript) can’t accurately represent 64-bit integers.
In JavaScript, integers are limited to 53 bits. This causes precision loss with large IDs:
// This loses precision!
const id = 10765432100123456789;
console.log(id.toString()); // "10765432100123458000" — wrong!
// Use strings instead
const id = "10765432100123456789";
console.log(id); // "10765432100123456789" — correct!
API versions
| Version | ID format |
|---|
| X API v2 | IDs are returned as strings by default |
| X API v1.1 | Returns both id (integer) and id_str (string) — always use id_str |
Working with IDs
Storing IDs
Store IDs as strings or 64-bit integers in your database:
| Database | Recommended type |
|---|
| PostgreSQL | BIGINT or TEXT |
| MySQL | BIGINT UNSIGNED or VARCHAR(20) |
| MongoDB | String |
| SQLite | TEXT (SQLite integers max at 63 bits) |
Comparing IDs
When comparing IDs for chronological ordering:
# Python - safe for 64-bit integers
if int(id1) > int(id2):
print("id1 is newer")
# JavaScript - compare as strings (lexicographically works for same-length IDs)
# Or use BigInt
if (BigInt(id1) > BigInt(id2)) {
console.log("id1 is newer");
}
Common ID types
| Object | Example ID | Notes |
|---|
| Post (Tweet) | 1234567890123456789 | Also called Tweet ID |
| User | 2244994945 | Older accounts have shorter IDs |
| List | 1234567890 | |
| Space | 1YqGodQbNXDxv | Alphanumeric, not Snowflake format |
| DM Event | 1234567890123456789 | |