Need to generate UUIDs in your application? This guide covers everything you need to know about UUID generation via API, including different UUID versions, use cases, and implementation examples in multiple languages.
What is a UUID?
A UUID (Universally Unique Identifier) is a 128-bit identifier that is guaranteed to be unique across all space and time. UUIDs are commonly used as database primary keys, session tokens, and unique identifiers in distributed systems.
A typical UUID looks like this: 550e8400-e29b-41d4-a716-446655440000
UUID Versions Explained
There are several UUID versions, each with different generation methods:
UUID v1 (Time-based)
Generated using the current timestamp and MAC address. Provides temporal ordering but exposes the generating machine's MAC address.
UUID v4 (Random)
Generated using random or pseudo-random numbers. Most commonly used version. Provides no temporal ordering but maximum privacy.
Using the UUID Generator API
TinyFn provides a simple endpoint to generate UUIDs:
GET https://api.tinyfn.io/v1/generate/uuid
Headers: X-API-Key: your-api-key
{
"uuid": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"version": 4
}
Parameters
| Parameter | Type | Description |
|---|---|---|
version |
integer | UUID version: 1 or 4 (default: 4) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/generate/uuid',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const { uuid } = await response.json();
console.log(uuid); // f47ac10b-58cc-4372-a567-0e02b2c3d479
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/generate/uuid',
headers={'X-API-Key': 'your-api-key'}
)
uuid = response.json()['uuid']
print(uuid) # f47ac10b-58cc-4372-a567-0e02b2c3d479
cURL
curl "https://api.tinyfn.io/v1/generate/uuid" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Database Primary Keys: Use UUIDs instead of auto-incrementing integers for distributed databases
- Session Tokens: Generate unique session identifiers
- File Names: Create unique file names for uploads
- API Request IDs: Track requests across microservices
- Order/Transaction IDs: Generate unique order numbers
Best Practices
- Use v4 for new projects: Random UUIDs are simpler and don't leak information
- Store as binary: UUIDs are 128 bits; storing as binary saves space vs. string
- Index appropriately: UUIDs don't cluster well; consider implications for database indexes
- Don't assume ordering: UUID v4 has no temporal ordering
Try the UUID Generator API
Get your free API key and start generating UUIDs in seconds.
Get Free API Key