Skip to main content
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.

ID format

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

VersionID format
X API v2IDs are returned as strings by default
X API v1.1Returns 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:
DatabaseRecommended type
PostgreSQLBIGINT or TEXT
MySQLBIGINT UNSIGNED or VARCHAR(20)
MongoDBString
SQLiteTEXT (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

ObjectExample IDNotes
Post (Tweet)1234567890123456789Also called Tweet ID
User2244994945Older accounts have shorter IDs
List1234567890
Space1YqGodQbNXDxvAlphanumeric, not Snowflake format
DM Event1234567890123456789

Data Dictionary

See ID fields for each object type.

Post Lookup

Retrieve posts by ID.