API Keys API

Manage API keys for authentication

The API Keys API allows you to manage API keys for users and organizations, including creating, listing, and deleting API keys.

List API keys

Retrieves a list of API keys for a user or organization.

List user API keys

GET /api-keys

List organization API keys

GET /api-keys

Query parameters

ParameterTypeDescription
organizationstringFilter by organization ID (optional)
userstringFilter by user ID (optional)

Response

{
  "keys": [
    {
      "id": "key_123",
      "name": "Production API Key",
      "preview": "xata_...",
      "created_at": "2024-01-01T00:00:00Z",
      "created_by": "user_123",
      "created_by_key": null,
      "expiry": "2025-01-01T00:00:00Z",
      "last_used": "2024-01-15T10:30:00Z",
      "scopes": ["read", "write"],
      "projects": ["proj_123"],
      "branches": ["br_123"]
    }
  ]
}

Create API key

Creates a new API key for a user or organization.

POST /api-keys

Request body

{
  "name": "New API Key",
  "expiry": "2025-01-01T00:00:00Z",
  "scopes": ["read", "write"],
  "projects": ["proj_123"],
  "branches": ["br_123"]
}

Request body parameters

ParameterTypeDescription
namestringHuman-readable name for the API key
expirystring (date-time)Optional expiration date for the API key
scopesarrayList of scopes for the API key
projectsarrayList of project IDs the key has access to
branchesarrayList of branch IDs the key has access to

Response

{
  "id": "key_123",
  "name": "New API Key",
  "key": "xata_live_abc123...",
  "created_at": "2024-01-01T00:00:00Z",
  "created_by": "user_123",
  "created_by_key": null,
  "expiry": "2025-01-01T00:00:00Z",
  "scopes": ["read", "write"],
  "projects": ["proj_123"],
  "branches": ["br_123"]
}

Get API key

Retrieves details about a specific API key.

GET /api-keys/{apiKeyID}

Path parameters

ParameterTypeDescription
apiKeyIDstringUnique identifier for the API key

Response

{
  "id": "key_123",
  "name": "Production API Key",
  "preview": "xata_...",
  "created_at": "2024-01-01T00:00:00Z",
  "created_by": "user_123",
  "created_by_key": null,
  "expiry": "2025-01-01T00:00:00Z",
  "last_used": "2024-01-15T10:30:00Z",
  "scopes": ["read", "write"],
  "projects": ["proj_123"],
  "branches": ["br_123"]
}

Delete API key

Permanently deletes an API key.

DELETE /api-keys/{apiKeyID}

Path parameters

ParameterTypeDescription
apiKeyIDstringUnique identifier for the API key

Response

Returns a 204 status code with no content on success.