API Endpoints
Complete reference for Gravatar API v3 endpoints and usage patterns.
Base URL
Section titled “Base URL”https://api.gravatar.com/v3Authentication
Section titled “Authentication”Use Bearer token authentication for all API requests:
Authorization: Bearer YOUR_API_KEYProfile Endpoints
Section titled “Profile Endpoints”Get Profile by Identifier
Section titled “Get Profile by Identifier”Retrieve a user’s profile using their email hash or profile URL slug.
Endpoint: GET /profiles/{profileIdentifier}
Authentication:
- Public: Limited profile data
- Bearer Token: Full profile data (recommended)
Parameters:
profileIdentifier(required): SHA256 hash of email or profile URL slug
Response Codes:
200 OK: Successfully retrieved profile404 Not Found: Profile not found429 Too Many Requests: Rate limit exceeded
Example Request
Section titled “Example Request”# With authenticationcurl -X GET "https://api.gravatar.com/v3/profiles/99511d6010af8c574c31f94e1b327bba5e25086dd7b92a4b6f3e132b579cc8d1" \ -H "Authorization: Bearer YOUR_API_KEY"Example Response
Section titled “Example Response”{ "hash": "99511d6010af8c574c31f94e1b327bba5e25086dd7b92a4b6f3e132b579cc8d1", "profile_url": "https://gravatar.com/examplefork", "avatar_url": "https://0.gravatar.com/avatar/99511d6010af8c574c31f94e1b327bba5e25086dd7b92a4b6f3e132b579cc8d1", "avatar_alt_text": "User's avatar", "display_name": "Example", "pronouns": "He/Him", "location": "E.G.", "job_title": "Chief", "company": "EG Inc", "description": "Sorry, this is not my name. Just an example, you know."}QR Code Endpoints
Section titled “QR Code Endpoints”Generate QR Code
Section titled “Generate QR Code”Generate a QR code for a user’s profile.
Endpoint: GET /qr-code/{sha256_hash}
Authentication: Public (no authentication required)
Parameters:
sha256_hash(required): SHA256 hash of email or profile URL slug
Query Parameters:
size(optional): Size of QR code in pixels (default: 80)version(optional): QR code style (1: standard, 3: modern dots)utm_medium(optional): UTM medium parameterutm_campaign(optional): UTM campaign parametertype(optional): Center icon type (user, gravatar, none)
Response Codes:
200 OK: QR code image (PNG format)429 Too Many Requests: Rate limit exceeded500 Internal Server Error: Server error
Example Request
Section titled “Example Request”curl -X GET "https://api.gravatar.com/v3/qr-code/99511d6010af8c574c31f94e1b327bba5e25086dd7b92a4b6f3e132b579cc8d1?size=300&type=user&version=3"Avatar URL Construction
Section titled “Avatar URL Construction”While not API endpoints, avatar URLs follow a predictable pattern:
Basic Avatar URL
Section titled “Basic Avatar URL”https://www.gravatar.com/avatar/{hash}?parametersURL Parameters
Section titled “URL Parameters”| Parameter | Description | Default |
|---|---|---|
s or size | Avatar size in pixels | 80 |
d or default | Default avatar type | mp |
r or rating | Maximum rating level | g |
f or forcedefault | Force default image | y |
Default Avatar Options
Section titled “Default Avatar Options”404- Return a 404 errormp- Mystery person silhouetteidenticon- Geometric pattern based on hashmonsterid- Generated monsterwavatar- Generated facesretro- 8-bit arcade-stylerobohash- Generated robotblank- Transparent PNG
Example Avatar URLs
Section titled “Example Avatar URLs”# Basic avatarhttps://www.gravatar.com/avatar/27205e5c51cb03f862138b22bcb5dc20f94a342e744ff6df1b8dc8af3c865109
# With parametershttps://www.gravatar.com/avatar/27205e5c51cb03f862138b22bcb5dc20f94a342e744ff6df1b8dc8af3c865109?s=200&r=pg&d=identicon
# Force defaulthttps://www.gravatar.com/avatar/27205e5c51cb03f862138b22bcb5dc20f94a342e744ff6df1b8dc8af3c865109?f=yData Formats
Section titled “Data Formats”Gravatar profiles can be requested in multiple formats:
JSON Format
Section titled “JSON Format”Append .json to profile URLs:
https://gravatar.com/99511d6010af8c574c31f94e1b327bba5e25086dd7b92a4b6f3e132b579cc8d1.jsonJSONP Support: Add a callback parameter:
https://gravatar.com/99511d6010af8c574c31f94e1b327bba5e25086dd7b92a4b6f3e132b579cc8d1.json?callback=processProfileXML Format
Section titled “XML Format”Append .xml to profile URLs:
https://gravatar.com/99511d6010af8c574c31f94e1b327bba5e25086dd7b92a4b6f3e132b579cc8d1.xmlPHP Serialized Format
Section titled “PHP Serialized Format”Append .php to profile URLs:
https://gravatar.com/99511d6010af8c574c31f94e1b327bba5e25086dd7b92a4b6f3e132b579cc8d1.phpVCF/vCard Format
Section titled “VCF/vCard Format”Append .vcf to profile URLs:
https://gravatar.com/99511d6010af8c574c31f94e1b327bba5e25086dd7b92a4b6f3e132b579cc8d1.vcfMarkdown Format
Section titled “Markdown Format”Append .md to profile URLs:
https://gravatar.com/99511d6010af8c574c31f94e1b327bba5e25086dd7b92a4b6f3e132b579cc8d1.mdRate Limiting
Section titled “Rate Limiting”Default Rate Limits
Section titled “Default Rate Limits”| Authentication | Requests per Hour |
|---|---|
| API Key | 1,000 |
| Public | Limited |
Rate Limit Headers
Section titled “Rate Limit Headers”All API responses include rate limit information:
X-RateLimit-Limit: Total requests allowed in current periodX-RateLimit-Remaining: Remaining requests in current periodX-RateLimit-Reset: Unix timestamp when the limit resets
Handling Rate Limits
Section titled “Handling Rate Limits”// Check rate limits from response headersconst response = await fetch('https://api.gravatar.com/v3/profiles/hash', { headers: { Authorization: `Bearer ${apiKey}`, },});
const rateLimit = { limit: response.headers.get('X-RateLimit-Limit'), remaining: response.headers.get('X-RateLimit-Remaining'), reset: response.headers.get('X-RateLimit-Reset'),};
if (rateLimit.remaining === '0') { const resetTime = parseInt(rateLimit.reset!) * 1000; const waitTime = resetTime - Date.now();
if (waitTime > 0) { console.log(`Rate limit reached. Waiting ${waitTime}ms...`); await new Promise((resolve) => setTimeout(resolve, waitTime)); }}Error Handling
Section titled “Error Handling”Error Response Format
Section titled “Error Response Format”All API errors follow a consistent format:
{ "error": "Error message description", "code": "error_code"}Common Error Codes
Section titled “Common Error Codes”| HTTP Status | Error Code | Description | Solution |
|---|---|---|---|
| 400 | uncropped_image | Image is not square | Crop image to 1:1 ratio |
| 400 | unsupported_image | File format not supported | Use JPG, PNG, or GIF |
| 401 | - | Authentication failed | Check API key |
| 403 | insufficient_scope | Token lacks permissions | Request proper scopes |
| 404 | disabled | Profile is disabled | No solution |
| 429 | rate_limit_exceeded | Too many requests | Implement backoff |
| 500 | - | Server error | Retry with backoff |
Error Handling Best Practices
Section titled “Error Handling Best Practices”import { GravatarError } from 'astro-gravatar';
try { const profile = await getProfile('user@example.com', { apiKey }); return profile;} catch (error) { if (error instanceof GravatarError) { switch (error.code) { case 'rate_limit_exceeded': // Implement exponential backoff await new Promise((resolve) => setTimeout(resolve, 5000)); return getProfile('user@example.com', { apiKey });
case 'disabled': // Profile is disabled, use fallback return createFallbackProfile();
default: console.error('Gravatar API Error:', error.message); throw error; } } throw error;}SDK and Tool Integration
Section titled “SDK and Tool Integration”astro-gravatar Integration
Section titled “astro-gravatar Integration”import { getProfile, buildAvatarUrl } from 'astro-gravatar';
// Get profile with API keyconst profile = await getProfile('user@example.com', { apiKey: import.meta.env.GRAVATAR_API_KEY,});
// Build avatar URLconst avatarUrl = buildAvatarUrl('user@example.com', { size: 200, rating: 'pg', default: 'identicon',});OpenAPI Specification
Section titled “OpenAPI Specification”The complete API specification is available at:
https://api.gravatar.com/v3/openapiUseful Resources
Section titled “Useful Resources”- GitHub Repositories: https://github.com/Automattic/gravatar
- Developer Dashboard: https://gravatar.com/developers
- API Console: https://gravatar.com/developers/console
- Status Page: https://automatticstatus.com/
Security Best Practices
Section titled “Security Best Practices”- Never expose API keys in client-side code
- Store API keys in environment variables
- Use HTTPS for all API requests
- Implement rate limiting on your side
- Validate email addresses before hashing
- Cache responses to reduce API calls
- Use exponential backoff for retries
- Monitor rate limit headers in responses
Next Steps
Section titled “Next Steps”- Authentication Guide - Set up API keys
- Component Reference - Learn component APIs
- Performance Guide - Optimize API usage