The Prime Generator API provides lightning-fast access to a pre-computed database of prime numbers. Get any prime by its index position with sub-10ms response times. The database grows dynamically as more primes are computed.
Database-driven lookups with intelligent caching - 1-8ms response times
Clean JSON responses with just the index and prime number
Simple HTTP GET requests with JSON responses
Get the nth prime number (1-indexed) from our 10 billion prime database.
Parameter | Type | Required | Description |
---|---|---|---|
pi |
integer | Yes | Prime index (1 to current maximum). Use /stats endpoint to check current limit. Example: pi=1 returns 2 (first prime) |
GET https://vincentmossman.com/prime-generator/api?pi=100
GET https://vincentmossman.com/prime-generator/api?pi=1000000
GET https://vincentmossman.com/prime-generator/api?pi=1000000000
// 100th prime { "index": 100, "prime": 541 } // 1 millionth prime { "index": 1000000, "prime": 15485863 } // 1 billionth prime { "index": 1000000000, "prime": 22801763489 }
Field | Type | Description |
---|---|---|
index |
integer | The requested prime index |
prime |
integer | The prime number at the given index |
Get current database statistics including maximum available prime index and build progress.
{ "database": { "max_prime_index": 55000000, "total_segments": 55, "status": "in_progress", "target_count": 10000000000 }, "cache": { "cacheSize": 5, "maxCacheSize": 100 }, "timestamp": "2025-08-05T15:30:45.123Z", "version": "2025-08-05-dynamic" }
{ "error": "Invalid prime index", "message": "Index must be between 1 and 55,000,000", "current_max": 55000000, "requested": 100000000, "suggestion": "Try a smaller index" "example": "/prime-generator/api?pi=5" }
{ "error": "Server busy - rate limit exceeded", "message": "Too many requests. Please try again in 1 second.", "limit": 5, "window": "1 second", "suggestion": "For bulk requests, add delays between calls" }
{ "error": "Prime lookup failed", "message": "Unable to retrieve the requested prime from database", "index": 15000000000 }
Test the API directly from this page. Enter a prime index and see the live response.
// Get the 1 millionth prime fetch('https://vincentmossman.com/prime-generator/api?pi=1000000') .then(response => response.json()) .then(data => { console.log(\`The ${data.index.toLocaleString()}th prime is: ${data.prime.toLocaleString()}\`); // Output: "The 1,000,000th prime is: 15,485,863" }) .catch(err => console.error('API Error:', err));
import requests import time # Test large prime lookup performance start = time.time() response = requests.get('https://vincentmossman.com/prime-generator/api?pi=500000000') data = response.json() end = time.time() print(f"The {data['index']:,}th prime is: {data['prime']:,}") print(f"Network + lookup time: {(end-start)*1000:.1f}ms") # Typical output: "Network + lookup time: 45.2ms"
# Get a large prime quickly curl "https://vincentmossman.com/prime-generator/api?pi=100000000" \ -H "Accept: application/json" \ -w "Response time: %{time_total}s\n" # Batch multiple requests for i in 1000000 10000000 100000000; do echo "Prime #$i:" curl -s "https://vincentmossman.com/prime-generator/api?pi=$i" | jq done