Every developer has been there: you need a unique identifier for a database row, a session token, or a distributed system event — and you reach for Math.random(). Don't. Math.random() is not cryptographically secure, collisions are possible, and it gives you no useful metadata.
This post walks you through a free UUID Generator API hosted on Cloudflare Workers that supports UUID v4, UUID v7 (time-ordered), ULID, NanoID, and custom ID formats — all in a single REST API, no API key required.
RapidAPI listing: UUID Generator API on RapidAPI
Why UUID v4 Is Not Always the Right Choice
UUID v4 is universally unique and random — perfect for most cases. But once you need to sort records by creation time or debug distributed systems, random IDs become painful. You can't tell which event happened first from a2f3c1d4-... vs b8e7f923-....
That's where UUID v7 and ULID come in:
| Format | Sortable? | Random bits | Use case |
|---|---|---|---|
| UUID v4 | No | 122 bits | General purpose |
| UUID v7 | Yes (time-prefix) | 74 bits | Databases, event logs |
| ULID | Yes (ms precision) | 80 bits | High-throughput systems |
| NanoID | No | Variable | Short URLs, tokens |
Getting Started — No API Key Needed
Base URL:
https://uuid-generator-api.miccho27-5ojagggbio.workers.dev
Or via RapidAPI (recommended for production — rate limits included):
https://uuid-generator-api.p.rapidapi.com
Generate UUID v4
The classic. Cryptographically random, globally unique.
curl:
curl "https://uuid-generator-api.p.rapidapi.com/v4" \
-H "X-RapidAPI-Key: YOUR_KEY" \
-H "X-RapidAPI-Host: uuid-generator-api.p.rapidapi.com"
JavaScript (fetch):
const response = await fetch(
"https://uuid-generator-api.p.rapidapi.com/v4",
{
headers: {
"X-RapidAPI-Key": "YOUR_RAPIDAPI_KEY",
"X-RapidAPI-Host": "uuid-generator-api.p.rapidapi.com",
},
}
);
const data = await response.json();
console.log(data.uuid);
// "550e8400-e29b-41d4-a716-446655440000"
Response:
{
"uuid": "a2f3c1d4-8b7e-4f92-b3c1-9d2e4f8a6b5c",
"version": 4,
"timestamp": "2026-04-02T10:15:30.000Z"
}
Generate UUID v7 — Time-Ordered IDs
UUID v7 (RFC 9562) embeds a millisecond timestamp in the first 48 bits. This means IDs generated later will always sort after earlier ones — perfect for database primary keys.
const response = await fetch(
"https://uuid-generator-api.p.rapidapi.com/v7",
{
headers: {
"X-RapidAPI-Key": "YOUR_RAPIDAPI_KEY",
"X-RapidAPI-Host": "uuid-generator-api.p.rapidapi.com",
},
}
);
const data = await response.json();
console.log(data.uuid);
// "01956ca4-8f20-7a3b-bc1e-9f2e4f8a6b5c"
// ^ first 8 chars encode the timestamp
In PostgreSQL, this lets you skip a separate created_at column for ordering:
SELECT * FROM events ORDER BY id; -- works correctly with UUID v7
Generate ULID — Lexicographically Sortable
ULID (Universally Unique Lexicographically Sortable Identifier) is a 26-character string that sorts correctly as a plain string — great for systems that don't support UUID natively.
curl "https://uuid-generator-api.p.rapidapi.com/ulid" \
-H "X-RapidAPI-Key: YOUR_KEY" \
-H "X-RapidAPI-Host: uuid-generator-api.p.rapidapi.com"
Response:
{
"ulid": "01HVMK3RZQFP4NTBTK7JMWC9Z0",
"timestamp": "2026-04-02T10:15:30.000Z"
}
The first 10 characters encode the timestamp — so "01HVMK3..." < "01HVMK4..." is chronological.
Generate NanoID — Short and URL-Safe
NanoID is a compact, URL-safe alternative to UUID. The default size is 21 characters, but you can customize it.
// Default size (21 chars)
const r1 = await fetch("https://uuid-generator-api.p.rapidapi.com/nanoid", {
headers: { "X-RapidAPI-Key": "YOUR_KEY", "X-RapidAPI-Host": "uuid-generator-api.p.rapidapi.com" }
});
// Custom size (10 chars for short URLs)
const r2 = await fetch("https://uuid-generator-api.p.rapidapi.com/nanoid?size=10", {
headers: { "X-RapidAPI-Key": "YOUR_KEY", "X-RapidAPI-Host": "uuid-generator-api.p.rapidapi.com" }
});
const short = await r2.json();
console.log(short.nanoid); // "V1StGXR8_Z"
Bulk Generation — Up to 1000 IDs at Once
Need to seed a database or generate test fixtures? Use the /bulk endpoint.
const response = await fetch(
"https://uuid-generator-api.p.rapidapi.com/bulk?type=v4&count=5",
{
headers: {
"X-RapidAPI-Key": "YOUR_KEY",
"X-RapidAPI-Host": "uuid-generator-api.p.rapidapi.com",
},
}
);
const data = await response.json();
console.log(data.ids);
// ["3f2504e0-...", "6ba7b810-...", "6ba7b811-...", "6ba7b812-...", "6ba7b813-..."]
Supported types: v4, v7, ulid, nanoid. Max count: 1000.
Custom IDs — Prefixed and Charset-Controlled
Need usr_abc123 style IDs for your SaaS app? The /custom POST endpoint has you covered.
const response = await fetch(
"https://uuid-generator-api.p.rapidapi.com/custom",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-RapidAPI-Key": "YOUR_KEY",
"X-RapidAPI-Host": "uuid-generator-api.p.rapidapi.com",
},
body: JSON.stringify({
prefix: "usr",
separator: "_",
length: 12,
charset: "alphanumeric",
count: 3,
}),
}
);
const data = await response.json();
console.log(data.ids);
// ["usr_aB3xK9mP2qRt", "usr_7fGhJ4nV1wZs", "usr_cDeLo5pQ8yUv"]
Available charsets: alphanumeric, numeric, hex, lowercase, uppercase.
UUID Validation
Paste in any UUID string to check if it's valid and detect its version.
const uuid = "550e8400-e29b-41d4-a716-446655440000";
const response = await fetch(
`https://uuid-generator-api.p.rapidapi.com/validate?uuid=${uuid}`,
{
headers: {
"X-RapidAPI-Key": "YOUR_KEY",
"X-RapidAPI-Host": "uuid-generator-api.p.rapidapi.com",
},
}
);
const data = await response.json();
console.log(data);
// { uuid: "550e8400-...", valid: true, version: 4 }
Real-World Integration Pattern
Here's a pattern for generating IDs on the server side via an API call, useful when your runtime doesn't have a native UUID implementation (e.g., some edge environments):
// id-service.js
const RAPIDAPI_KEY = process.env.RAPIDAPI_KEY;
const BASE_URL = "https://uuid-generator-api.p.rapidapi.com";
const HEADERS = {
"X-RapidAPI-Key": RAPIDAPI_KEY,
"X-RapidAPI-Host": "uuid-generator-api.p.rapidapi.com",
};
export async function generateId(type = "v7") {
const res = await fetch(`${BASE_URL}/${type}`, { headers: HEADERS });
if (!res.ok) throw new Error(`ID generation failed: ${res.status}`);
const data = await res.json();
return data.uuid || data.ulid || data.nanoid;
}
export async function generateBulkIds(count = 100, type = "v4") {
const res = await fetch(
`${BASE_URL}/bulk?type=${type}&count=${count}`,
{ headers: HEADERS }
);
const data = await res.json();
return data.ids;
}
// Usage
const sessionId = await generateId("nanoid"); // short URL-safe token
const recordId = await generateId("v7"); // sortable DB primary key
const testIds = await generateBulkIds(50, "v4"); // test fixture data
Summary
| Endpoint | Method | Returns |
|---|---|---|
/v4 |
GET | UUID v4 |
/v7 |
GET | UUID v7 (time-ordered) |
/ulid |
GET | ULID |
/nanoid?size=N |
GET | NanoID |
/bulk?type=X&count=N |
GET | Array of IDs |
/custom |
POST | Prefixed custom IDs |
/validate?uuid=X |
GET | Validation result |
Free tier: 100 requests/day. Upgrade on RapidAPI for higher limits.
If you found this useful, check out the full collection of 40+ free APIs I've built on Cloudflare Workers — all with free tiers, no credit card required.
Top comments (0)