A robust, layered bird facts API that provides regionally-relevant bird information with fun facts and rich descriptions.
Visit the API at: https://your-val-url.web.val.run
Get a random bird fact with regional relevance.
Query Parameters:
region (optional): Region code (e.g., "US-CA" for California)lat (optional): Latitude for location-based resultslng (optional): Longitude for location-based resultsExample Requests:
# Random bird from anywhere GET /api/birds/random # Birds from California GET /api/birds/random?region=US-CA # Birds near San Francisco GET /api/birds/random?lat=37.7749&lng=-122.4194
Get birds observed in a specific region.
Get information for a specific bird species.
Get random structured facts from the pre-collected database (fast response).
Query Parameters:
count (optional): Number of facts to return (1-10, default: 1)category (optional): Filter by category (behavior, appearance, habitat, diet, reproduction, migration, general)region (optional): Filter by region codeExample Requests:
# Get 5 random facts GET /api/facts/random?count=5 # Get behavior facts from California GET /api/facts/random?count=3&category=behavior®ion=US-CA # Get migration facts GET /api/facts/random?category=migration
Response:
{ "facts": [ { "id": "abc123", "name": "American Robin", "scientificName": "Turdus migratorius", "fact": "American robins are known for their distinctive red breast...", "category": "appearance", "source": "wikipedia", "region": "US-CA", "imageUrl": "https://upload.wikimedia.org/...", "wikipediaUrl": "https://en.wikipedia.org/wiki/American_robin", "collectedAt": "2025-06-29T06:00:00.000Z", "tags": ["american robin", "colorful", "common"] } ], "count": 1, "filters": { "category": "appearance", "region": "US-CA" } }
Get AI-curated superlative facts with quality scoring.
Query Parameters:
count (optional): Number of facts to return (1-50, default: 10)minQuality (optional): Minimum quality score (1-10, default: 7)category (optional): Filter by categoryuniqueness (optional): Filter by uniqueness level (interesting, extraordinary)Example Requests:
# Get 10 highest quality facts GET /api/facts/superlative?minQuality=8 # Get extraordinary behavior facts GET /api/facts/superlative?category=behavior&uniqueness=extraordinary # Get top 20 superlative facts GET /api/facts/superlative?count=20&minQuality=9
Response:
{ "facts": [ { "originalFact": "The original fact text", "enhancedFact": "AI-enhanced version with better clarity and impact", "birdName": "Arctic Tern", "scientificName": "Sterna paradisaea", "qualityScore": 9.2, "superlativeAspects": ["record-breaking migration", "extreme endurance"], "reasoning": "This fact represents the longest migration in the animal kingdom...", "category": "behavior", "emotionalImpact": "high", "uniqueness": "extraordinary", "filteredAt": "2025-06-29T06:00:00.000Z", "region": "Arctic", "imageUrl": "https://upload.wikimedia.org/...", "wikipediaUrl": "https://en.wikipedia.org/wiki/Arctic_tern" } ], "count": 1, "filters": { "minQuality": 8, "category": "all", "uniqueness": "all" } }
Get the top superlative facts with an AI-generated nature documentary summary.
Query Parameters:
count (optional): Number of top facts to return (default: 20)Response:
{ "facts": [...], // Array of top superlative facts "summary": "In the vast tapestry of avian evolution, these remarkable creatures showcase nature's most extraordinary innovations...", "count": 20 }
Get comprehensive statistics about the AI-curated superlative facts collection.
Response:
{ "totalFacts": 156, "averageQuality": 8.3, "lastUpdated": "2025-06-29T06:00:00.000Z", "topCategories": { "behavior": 45, "physiology": 32, "ecology": 28, ... }, "qualityDistribution": { "9-10": 23, "8-9": 67, "7-8": 66 }, "topBirds": [ { "name": "Arctic Tern", "count": 3, "avgQuality": 9.1 } ] }
Get statistics about the facts collection.
Response:
{ "totalFacts": 847, "lastUpdated": "2025-06-29T06:00:00.000Z", "regions": ["US-CA", "US-NY", "GB", "AU", ...], "categories": { "behavior": 156, "appearance": 134, "habitat": 98, ... }, "sources": { "wikipedia": 423, "api_ninjas": 234, "curated": 190 } }
Manually trigger facts collection (for testing/admin use).
Health check endpoint.
The API works without API keys but provides enhanced functionality with them:
EBIRD_API_KEY: eBird API key for higher rate limitsAPI_NINJAS_KEY: API Ninjas key for additional factsCommon region codes for the eBird API:
US-CA - California, USAUS-NY - New York, USAGB - United KingdomAU - AustraliaCA-ON - Ontario, Canada// Get random regional bird
const response = await fetch('/api/birds/random?region=US-CA');
const bird = await response.json();
console.log(`${bird.name}: ${bird.fact}`);
// Get bird by coordinates
const nearbyBird = await fetch('/api/birds/random?lat=40.7128&lng=-74.0060');
const birdData = await nearbyBird.json();
import requests # Get random bird fact response = requests.get('https://your-api-url/api/birds/random') bird = response.json() print(f"{bird['name']}: {bird['fact']}") # Get regional birds regional_response = requests.get('https://your-api-url/api/birds/region/US-CA') birds = regional_response.json()
# Random bird fact curl "https://your-api-url/api/birds/random" # Regional bird with coordinates curl "https://your-api-url/api/birds/random?lat=37.7749&lng=-122.4194" # Specific bird species curl "https://your-api-url/api/birds/species/Blue%20Jay"
| Field | Type | Description |
|---|---|---|
name | string | Common bird name |
scientificName | string | Scientific/Latin name |
fact | string | Interesting fact about the bird |
wikipedia.summary | string | Wikipedia summary |
wikipedia.image | string | Image URL |
wikipedia.url | string | Wikipedia page URL |
region | string | Region or coordinates used |
source | string | "regional" or "fallback" |
cached | boolean | Whether result was cached |
The API includes comprehensive logging and error tracking:
This microservice demonstrates best practices for:
Open source - feel free to adapt for your own projects!