Creates a new API key that can be used to authenticate API requests. The key will be returned in the response and cannot be retrieved again after creation.
Secret keys are only shown once. Make sure to copy and store the key securely before closing this response.
Request Body
A descriptive name for the API key to help identify its purpose
The type of API key to create
pk - Public key (safe for browser use)
sk - Secret key (server-to-server only)
The environment for this API key
test - For development and testing
live - For production use
The UUID of the team this API key belongs to
Array of permission scopes for this key. Defaults to ["enc.tiles:read"]
enc.tiles:read - Access chart tile imagery
enc.mbtiles:download - Download offline chart packages
interact.identify:read - Identify chart features
features.search:read - Search chart features
query.spatial:read - Perform spatial queries
keys.manage - Manage API keys (secret keys only)
team.manage - Manage team settings (secret keys only)
Allowed domains for public keys (CORS + referer check)
https://example.com - Exact domain match
https://*.example.com - Wildcard subdomain match
http://localhost:3000 - Local development
Array of allowed IP addresses or CIDR blocks
192.168.1.1 - Single IP address
192.168.1.0/24 - CIDR block
2001:db8::/32 - IPv6 CIDR block
Custom rate limit for this key (requests per hour). Defaults to plan limit.
ISO 8601 timestamp when the key should expire (optional)
Additional description or notes about this API key
Response
Unique identifier for the API key
The full API key (only returned once on creation)
The first 20 characters of the key for identification
The type of key (pk or sk)
The environment (test or live)
UUID of the team that owns this key
Array of granted permission scopes
Allowed domains (for public keys)
Allowed IP addresses or CIDR blocks
Rate limit for this key (requests per hour)
Whether the key is currently active
ISO 8601 timestamp when the key expires (if set)
UUID of the user who created this key
ISO 8601 timestamp when the key was created
ISO 8601 timestamp when the key was last used (null if never used)
curl -X POST https://nmixhdvexhgizmxlnhqi.supabase.co/functions/v1/generate-api-key \
-H "Authorization: Bearer chrt_sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"name": "Production Frontend Key",
"type": "pk",
"environment": "live",
"team_id": "team_abc123",
"scopes": ["enc.tiles:read", "interact.identify:read"],
"domains": ["https://myapp.com", "https://*.myapp.com"],
"description": "Public key for production web application"
}'
Success Response
Error Response
{
"data" : {
"id" : "key_abc123def456" ,
"name" : "Production Frontend Key" ,
"key" : "chrt_pk_live_myteam_ABC123DEF456GHI789..." ,
"key_prefix" : "chrt_pk_live_myteam_" ,
"type" : "pk" ,
"environment" : "live" ,
"team_id" : "team_abc123" ,
"scopes" : [ "enc.tiles:read" , "interact.identify:read" ],
"domains" : [ "https://myapp.com" , "https://*.myapp.com" ],
"ip_whitelist" : [],
"rate_limit" : 10000 ,
"is_active" : true ,
"expires_at" : null ,
"created_by" : "user_xyz789" ,
"created_at" : "2024-01-15T10:30:00Z" ,
"last_used_at" : null ,
"description" : "Public key for production web application"
},
"meta" : {
"timestamp" : "2024-01-15T10:30:00Z" ,
"request_id" : "req_abc123"
}
}
Security Considerations
Always set domain restrictions for public keys to prevent unauthorized use:
Use specific domains rather than wildcards when possible
Include all subdomains you need with *.domain.com patterns
Consider IP restrictions for additional security
Follow the principle of least privilege:
Grant only the minimum scopes required for your use case
Use separate keys for different parts of your application
Regularly audit and remove unused scopes
Store secret keys in environment variables or secure vaults
Never commit keys to version control
Use different keys for development, staging, and production
Set up key rotation schedules
Common Use Cases
Frontend Public Key {
"name" : "React App" ,
"type" : "pk" ,
"environment" : "live" ,
"scopes" : [ "enc.tiles:read" , "interact.identify:read" ],
"domains" : [ "https://myapp.com" ]
}
Backend Secret Key {
"name" : "API Server" ,
"type" : "sk" ,
"environment" : "live" ,
"scopes" : [ "enc.*:read" , "keys.manage" ],
"ip_whitelist" : [ "10.0.0.0/8" ]
}