Skip to main content

Create API Key

Create a new API key for programmatic access to EntryGuard. The full API key secret is only shown once upon creation and cannot be retrieved later.

Note: This feature is only available for organizations on the paid plan.

Request

POST /api-keys

Authentication

Requires an Admin Bearer JWT token.

Authorization: Bearer <access_token>

Request Body

{
"name": "CI/CD Pipeline Key",
"description": "API key for automated deployments",
"scopes": ["sessions:read", "sessions:write"],
"expiresAt": "2026-12-31T23:59:59Z"
}

Request Fields

FieldTypeRequiredDescription
namestringYesHuman-readable name for the key (max 255 characters)
descriptionstringNoOptional description of the key's purpose
scopesstring[]YesArray of permission scopes (must be non-empty)
expiresAtstringNoISO timestamp when the key should expire (null for no expiration)

Available Scopes

ScopeDescription
sessions:readRead session data
sessions:writeCreate and manage sessions
resources:readRead resource data
audit:readRead audit logs

Response

Returns the created API key object including the plain text key secret.

Success Response

Status Code: 201 Created

Response Body:

{
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "CI/CD Pipeline Key",
"description": "API key for automated deployments",
"keyPrefix": "egk_live_abc123",
"plainTextKey": "egk_live_abc123def456ghi789jkl012mno345pqr678stu901vwx234yz",
"scopes": ["sessions:read", "sessions:write"],
"expiresAt": "2026-12-31T23:59:59Z",
"createdAt": "2026-02-18T10:30:00Z"
}

Response Fields

FieldTypeDescription
idUUIDUnique identifier for the API key
namestringHuman-readable name for the key
descriptionstringOptional description
keyPrefixstringFirst few characters of the key for identification
plainTextKeystringFull API key secret (shown only once)
scopesstring[]Array of permission scopes granted to this key
expiresAtstringISO timestamp when key expires (null if no expiration)
createdAtstringISO timestamp of creation

Errors

Status CodeError CodeDescription
400BAD_REQUESTInvalid request body or missing required fields
401UNAUTHORIZEDMissing or invalid JWT token
403FORBIDDENUser does not have admin privileges or organization is not on the paid plan
422UNPROCESSABLE_ENTITYInvalid scope values or validation errors

Example

Request

curl -X POST https://api.entryguard.io/api/v1/api-keys \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-d '{
"name": "CI/CD Pipeline Key",
"description": "API key for automated deployments",
"scopes": ["sessions:read", "sessions:write"],
"expiresAt": "2026-12-31T23:59:59Z"
}'

Response

{
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "CI/CD Pipeline Key",
"description": "API key for automated deployments",
"keyPrefix": "egk_live_abc123",
"plainTextKey": "egk_live_abc123def456ghi789jkl012mno345pqr678stu901vwx234yz",
"scopes": ["sessions:read", "sessions:write"],
"expiresAt": "2026-12-31T23:59:59Z",
"createdAt": "2026-02-18T10:30:00Z"
}

Important: Store the plainTextKey securely. It will never be displayed again. If you lose it, you must create a new API key.