API Keys
Create, list, update, regenerate, and revoke API keys programmatically. Manage your API keys through the dashboard or via these endpoints.
Bearer Token Authentication
Authorization: Bearer header with your JWT from your dashboard login, not the x-api-key header. These are dashboard-level operations for managing your API keys. The API keys themselves are used with x-api-key for render and other API calls.Endpoints Overview
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/api-keys | Create a new API key |
| GET | /api/v1/api-keys | List all API keys |
| PATCH | /api/v1/api-keys/{key_id} | Update API key name |
| DELETE | /api/v1/api-keys/{key_id} | Revoke an API key |
| POST | /api/v1/api-keys/{key_id}/regenerate | Regenerate an API key |
Create API Key
/api/v1/api-keysGenerate a new API key. Store the key value securely as soon as you receive it.
Save Your Key Immediately
sm_****<last4>.Headers
AuthorizationstringRequiredBearer token: a JWT from your dashboard login (e.g., 'Bearer eyJhbGci...')
Content-TypestringRequiredMust be application/json
Request Body
namestringRequiredDescriptive name for the API key (1-255 characters). Examples: 'Production API', 'Development', 'Staging Server'.
expires_in_daysintegerNumber of days until the key expires (1-3650). If omitted or null, the key never expires.
1{2 "name": "Production API",3 "expires_in_days": 3654}
Response
1{2 "id": "123e4567-e89b-12d3-a456-426614174000",3 "name": "Production API",4 "key": "sm_a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",5 "is_active": true,6 "last_used_at": null,7 "created_at": "2026-03-22T10:00:00Z",8 "updated_at": null,9 "revoked_at": null,10 "expires_at": "2027-03-22T10:00:00Z"11}
Response Fields
idstring (UUID)RequiredUnique identifier for the API key. Use this ID for update, delete, and regenerate operations.
namestringRequiredThe name you assigned to the key.
keystringRequiredThe API key starting with 'sm_'. Full value returned only at creation and regeneration; all other responses return a masked sm_****<last4>.
is_activebooleanRequiredWhether the key is currently active. Always true for newly created keys.
last_used_atstring (ISO 8601) | nullTimestamp of when the key was last used for an API call. Null if never used.
created_atstring (ISO 8601)RequiredTimestamp of when the key was created.
updated_atstring (ISO 8601) | nullTimestamp of when the key metadata was last updated (e.g., name change). Null for newly created keys.
revoked_atstring (ISO 8601) | nullTimestamp of when the key was revoked. Null for active keys.
expires_atstring (ISO 8601) | nullTimestamp of when the key expires. Null if the key never expires.
Code Examples
1curl -X POST "https://api.sudomock.com/api/v1/api-keys" \2 -H "Content-Type: application/json" \3 -H "Authorization: Bearer YOUR_SUPABASE_JWT" \4 -d '{5 "name": "Production API",6 "expires_in_days": 3657 }'
Error Responses
Returned when the Bearer token is missing, malformed, or invalid. The detail message varies:
1// Missing Authorization header entirely2{ "detail": "Missing Authorization header", "success": false }34// Malformed header (not "Bearer <token>" format)5{ "detail": "Invalid Authorization header format. Expected: 'Bearer <token>'", "success": false }67// Expired or invalid JWT token8{ "detail": "Invalid or expired token", "success": false }910// Server-side token validation failure11{ "detail": "Token validation failed", "success": false }
1{2 "detail": "Validation error",3 "errors": [4 {5 "field": "body -> name",6 "message": "Missing required field: body -> name"7 }8 ],9 "success": false10}
1{2 "detail": "Internal error while creating API key",3 "success": false4}
List API Keys
/api/v1/api-keysRetrieve all API keys for the authenticated user. Returns both active and revoked keys, ordered by creation date (newest first). Useful for displaying key management interfaces.
Headers
AuthorizationstringRequiredBearer token: a JWT from your dashboard login
Response
1{2 "keys": [3 {4 "id": "123e4567-e89b-12d3-a456-426614174000",5 "name": "Production API",6 "key": "sm_****a1b2",7 "is_active": true,8 "last_used_at": "2026-03-22T14:30:00Z",9 "created_at": "2026-03-01T08:00:00Z",10 "updated_at": "2026-03-15T12:00:00Z",11 "revoked_at": null,12 "expires_at": "2027-03-01T08:00:00Z"13 },14 {15 "id": "987fcdeb-51a2-43e7-b890-123456789abc",16 "name": "Development",17 "key": "sm_****f8e7",18 "is_active": true,19 "last_used_at": null,20 "created_at": "2026-03-20T09:00:00Z",21 "updated_at": null,22 "revoked_at": null,23 "expires_at": null24 }25 ],26 "total": 227}
Response Fields
keysarrayRequiredArray of API key objects. Each object contains the same fields as the create response (id, name, key, is_active, last_used_at, created_at, updated_at, revoked_at, expires_at). The key value is masked as sm_****<last4>.
totalintegerRequiredTotal number of API keys (includes both active and revoked keys).
Code Examples
1curl -X GET "https://api.sudomock.com/api/v1/api-keys" \2 -H "Authorization: Bearer YOUR_SUPABASE_JWT"
Error Responses
1{2 "detail": "Missing Authorization header",3 "success": false4}
Other possible messages: Invalid Authorization header format. Expected: 'Bearer <token>', Invalid or expired token, Token validation failed.
1{2 "detail": "Internal error while listing API keys",3 "success": false4}
Update API Key
/api/v1/api-keys/{key_id}Update the name of an existing API key. This does not affect the key value itself or its active status.
Headers
AuthorizationstringRequiredBearer token: a JWT from your dashboard login
Content-TypestringRequiredMust be application/json
Path Parameters
key_idstring (UUID)RequiredThe UUID of the API key to update (from the create or list response).
Request Body
namestringRequiredNew name for the API key (1-255 characters).
1{2 "name": "Production API v2"3}
Response
1{2 "id": "123e4567-e89b-12d3-a456-426614174000",3 "name": "Production API v2",4 "key": "sm_****a1b2",5 "is_active": true,6 "last_used_at": "2026-03-22T14:30:00Z",7 "created_at": "2026-03-01T08:00:00Z",8 "updated_at": "2026-03-22T15:00:00Z",9 "revoked_at": null,10 "expires_at": "2027-03-01T08:00:00Z"11}
Code Examples
1curl -X PATCH "https://api.sudomock.com/api/v1/api-keys/123e4567-e89b-12d3-a456-426614174000" \2 -H "Content-Type: application/json" \3 -H "Authorization: Bearer YOUR_SUPABASE_JWT" \4 -d '{5 "name": "Production API v2"6 }'
Error Responses
1{2 "detail": "Missing Authorization header",3 "success": false4}
Other possible messages: Invalid Authorization header format. Expected: 'Bearer <token>', Invalid or expired token, Token validation failed.
1{2 "detail": "Validation error",3 "errors": [4 {5 "field": "body -> name",6 "message": "Missing required field: body -> name"7 }8 ],9 "success": false10}
1{2 "detail": "API key not found",3 "success": false4}
1{2 "detail": "Internal error while updating API key",3 "success": false4}
Revoke API Key
/api/v1/api-keys/{key_id}Revoke (deactivate) an API key. The key will immediately stop working for authentication. This action cannot be undone. The revoked key will still appear in the list response with is_active: false.
Immediate Invalidation
Headers
AuthorizationstringRequiredBearer token: a JWT from your dashboard login
Path Parameters
key_idstring (UUID)RequiredThe UUID of the API key to revoke.
Response
Returns no body on success. The HTTP status code 204 confirms the key has been revoked.
Code Examples
1curl -X DELETE "https://api.sudomock.com/api/v1/api-keys/123e4567-e89b-12d3-a456-426614174000" \2 -H "Authorization: Bearer YOUR_SUPABASE_JWT"
Error Responses
1{2 "detail": "Missing Authorization header",3 "success": false4}
Other possible messages: Invalid Authorization header format. Expected: 'Bearer <token>', Invalid or expired token, Token validation failed.
1{2 "detail": "API key not found",3 "success": false4}
1{2 "detail": "Internal error while revoking API key",3 "success": false4}
Regenerate API Key
/api/v1/api-keys/{key_id}/regenerateRegenerate an API key. This revokes the old key immediately and creates a new one with the same name. If the original key had an expiration, the new key gets the same duration starting from now. The new key has a new UUID.
Old Key Immediately Revoked
Headers
AuthorizationstringRequiredBearer token: a JWT from your dashboard login
Path Parameters
key_idstring (UUID)RequiredThe UUID of the API key to regenerate.
Response
1{2 "id": "aabbccdd-1122-3344-5566-778899aabbcc",3 "name": "Production API v2",4 "key": "sm_9f8e7d6c5b4a3029182736455463728190a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5",5 "is_active": true,6 "last_used_at": null,7 "created_at": "2026-03-22T16:00:00Z",8 "updated_at": null,9 "revoked_at": null,10 "expires_at": "2027-03-22T16:00:00Z"11}
The response contains the new key with a new UUID. The response fields are identical to the create response. The old key's id is now revoked and no longer usable.
Code Examples
1curl -X POST "https://api.sudomock.com/api/v1/api-keys/123e4567-e89b-12d3-a456-426614174000/regenerate" \2 -H "Authorization: Bearer YOUR_SUPABASE_JWT"
Error Responses
1{2 "detail": "Missing Authorization header",3 "success": false4}
Other possible messages: Invalid Authorization header format. Expected: 'Bearer <token>', Invalid or expired token, Token validation failed.
1{2 "detail": "API key not found",3 "success": false4}
1{2 "detail": "Internal error while regenerating API key",3 "success": false4}
Key Format
All SudoMock API keys follow a consistent format:
1sm_a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b22| | |3| +--- 64 hex characters (32 random bytes) ------------------------+4|5sm_ prefix (identifies SudoMock keys)
| Component | Value | Description |
|---|---|---|
| Prefix | sm_ | Identifies the key as a SudoMock API key |
| Random part | 64 hex characters | Cryptographically random, generated from 32 bytes |
| Total length | 67 characters | Prefix (3) + random (64) |
Best Practices
.env files, secret managers, or your platform's environment variable configuration.expires_in_days to automatically expire keys. This reduces risk if a key is compromised. 365 days is a good default for production keys.Key Rotation Workflow