AnvilJSON utilities

Anvil › Docs › /v1/uuid

UUID generator API: random v4 and time-ordered v7 UUIDs

A UUID is a 128-bit identifier written as 36 characters, like 019a4b1e-7c2f-7d10-9f3a-2b6c1e8d4a51. You can create one anywhere without asking a central database, and the chance of two ever clashing is so small it can be ignored. This endpoint hands you fresh ones in either of the two versions people actually use today.

In one line: GET /v1/uuid?version=7&count=3 returns JSON. No key, CORS on, 60 requests a minute.
GET

/v1/uuid

Random UUIDs (v4) or time-ordered UUIDs (v7). Change the values and press Send request to call the live API.

Parameters

NameTypeWhat it doesDefault
versioninteger4 (random) or 7 (time-ordered, sorts by creation time)4
countintegerHow many, 1 to 1001
upperbooleanUppercase hexfalse

Example

Request:

GET https://api.oddlathe.com/v1/uuid?version=7&count=3

Response (generated by the real code when these docs were last built; random or time-based values will differ for you):

{
 "version": 7,
 "uuids": [
  "01a1cd58-085e-7232-bab6-22485c6d7a39",
  "01a1cd58-085e-7c2e-985d-fb5f1d45e599",
  "01a1cd58-085e-784d-b344-0d1678bbe3ad"
 ]
}

Code examples

curl
curl 'https://api.oddlathe.com/v1/uuid?version=7&count=3'
JavaScript (browser or Node 18+)
const params = new URLSearchParams({
  version: "7",
  count: "3"
});
const res = await fetch(`https://api.oddlathe.com/v1/uuid?${params}`);
if (!res.ok) throw new Error((await res.json()).error.message);
const data = await res.json();
console.log(data);
Python (standard library only)
import json, urllib.parse, urllib.request

params = urllib.parse.urlencode({"version": "7", "count": "3"})
url = "https://api.oddlathe.com/v1/uuid?" + params
# Send a User-Agent: the edge network refuses Python's default one.
req = urllib.request.Request(url, headers={"User-Agent": "my-script/1.0"})
with urllib.request.urlopen(req, timeout=10) as r:
    data = json.load(r)
print(data)

When it's useful

  • Primary keys for database rows created by many machines at once
  • Idempotency keys for payment or webhook retries
  • Test fixtures and seed data in a shell script or spreadsheet
  • Correlation IDs that follow one request through several services

Good to know

  • Version 4 is 122 random bits. It reveals nothing, which is good for public IDs, but the values are scattered, so B-tree indexes split pages and grow faster.
  • Version 7 (RFC 9562) starts with a 48-bit Unix timestamp in milliseconds, then random bits. New IDs sort after old ones, so inserts stay at the end of the index. The trade-off: anyone holding the ID can read roughly when it was made.
  • Both versions use the operating system's cryptographic random source. Responses are marked no-store so no cache hands the same ID to two callers.

v7 UUIDs put a millisecond timestamp in the first 48 bits, so they sort by creation time and index well in databases. v4 is 122 random bits.

Errors

Errors are JSON like {"error": {"code": "…", "message": "…"}}. The ones this endpoint can return:

  • bad_param (400): a value is the wrong type or out of range (the message says which)
  • rate_limited (429): over 60 requests a minute; wait for Retry-After seconds

Questions

Should I use UUID v4 or v7?

Use v7 for database keys where insert speed and natural ordering matter. Use v4 when the ID is public and you'd rather not reveal when something was created.

Can two UUIDs ever be the same?

In theory yes, in practice no. With v4 you would need to generate about a billion per second for 85 years for a 50% chance of a single duplicate.

Is a UUID a secret or a password?

No. It's unpredictable, but it is an identifier, not a credential. Don't use one as the only thing protecting a private link unless you understand that anyone who sees the URL can use it.

Can I generate UUIDs without an API?

Yes: crypto.randomUUID() in browsers and Node, uuid.uuid4() in Python, uuidgen on most systems. The API is handy in no-code tools, spreadsheets and quick scripts.

Related endpoints

Prefer a page to an API?

Published · OpenAPI 3.1 spec · Limits and privacy