AnvilJSON utilities

Anvil › Docs › /v1/nanoid

Nano ID API: short URL-safe random IDs

A Nano ID is 21 characters drawn from A–Z, a–z, 0–9, _ and -. That is 126 random bits, almost the same as a UUID v4, in a string short enough to sit comfortably in a URL.

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

/v1/nanoid

Short URL-safe random IDs (21 chars, 126 bits). Change the values and press Send request to call the live API.

Parameters

NameTypeWhat it doesDefault
countintegerHow many, 1 to 1001

Example

Request:

GET https://api.oddlathe.com/v1/nanoid?count=3

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

{
 "ids": [
  "oN2sloofn6ZXMuyl48u4D",
  "8IPtYH_bUjNYW20NHZQCC",
  "0GrlMg0fyFaC8hWcfKsar"
 ]
}

Code examples

curl
curl 'https://api.oddlathe.com/v1/nanoid?count=3'
JavaScript (browser or Node 18+)
const params = new URLSearchParams({
  count: "3"
});
const res = await fetch(`https://api.oddlathe.com/v1/nanoid?${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({"count": "3"})
url = "https://api.oddlathe.com/v1/nanoid?" + 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

  • Share links and invite codes
  • Client-side record IDs in apps that sync later
  • Short unguessable file names for uploads

Good to know

  • Every character is chosen with the cryptographic random generator and no modulo bias.
  • Nano IDs carry no time information, so they don't sort in any meaningful order.

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

Is 21 characters enough?

At 1,000 IDs per hour you'd need about 149 billion years for a 1% chance of a single collision.

Why are there underscores and hyphens?

They're the two URL-safe symbols, which takes the alphabet to 64 characters: exactly 6 bits per character.

Related endpoints

Published · OpenAPI 3.1 spec · Limits and privacy