Skip to content

API Key Management

Manage API keys through the Management API. Requires JWT authentication.


Creates a new API key.

Request:

{
"name": "Production API Key",
"scopes": ["database:read", "database:write"],
"expiresAt": "2025-01-15T00:00:00Z"
}
FieldTypeRequiredDescription
namestringYesDescriptive name for the key
scopesarrayYesPermission scopes
expiresAtdatetimeNoExpiration date (optional)

Response (201 Created):

{
"keyId": "key_abc123",
"apiKey": "ts_live_abc123xyz789...",
"name": "Production API Key",
"scopes": ["database:read", "database:write"],
"createdAt": "2024-01-15T10:00:00Z",
"expiresAt": "2025-01-15T00:00:00Z"
}

Lists all API keys (without the actual key values).

Response (200 OK):

{
"keys": [
{
"keyId": "key_abc123",
"keyPrefix": "ts_live_abc...",
"name": "Production API Key",
"scopes": ["database:read", "database:write"],
"createdAt": "2024-01-15T10:00:00Z",
"expiresAt": "2025-01-15T00:00:00Z",
"lastUsedAt": "2024-01-15T12:00:00Z",
"revoked": false
}
],
"nextCursor": null
}

Revokes an API key. The key will immediately stop working.

Response (204 No Content): Empty body on success.


ScopeDescription
database:readRead items from databases
database:writeWrite/delete items in databases
database:*Full database access
repository:readRead entities from repositories
repository:writeWrite/delete entities in repositories
repository:*Full repository access
*Full access to all operations
// Read-only access
{ "scopes": ["database:read", "repository:read"] }
// Full database access
{ "scopes": ["database:*"] }
// Full access
{ "scopes": ["*"] }

PrefixEnvironment
ts_live_Production
ts_test_Testing/Development

// Create API key
var createResult = await client.ApiKeys.CreateAsync(new CreateApiKeyRequest(
Name: "Production API Key",
Scopes: new[] { "database:read", "database:write" },
ExpiresAt: DateTime.UtcNow.AddYears(1)
));
if (createResult.IsSuccess)
{
// Important: Save this key - it's only shown once!
Console.WriteLine($"API Key: {createResult.Value.ApiKey}");
Console.WriteLine($"Key ID: {createResult.Value.KeyId}");
}
// List API keys
var listResult = await client.ApiKeys.ListAsync();
foreach (var key in listResult.Value.Keys)
{
var status = key.Revoked ? "Revoked" :
key.ExpiresAt < DateTime.UtcNow ? "Expired" : "Active";
Console.WriteLine($"{key.Name} ({key.KeyPrefix}...) - \{status\}");
}
// Revoke API key
var revokeResult = await client.ApiKeys.RevokeAsync("key_abc123");
if (revokeResult.IsSuccess)
{
Console.WriteLine("API key revoked");
}

Only grant permissions your application needs:

// Good: Specific scopes
{ "scopes": ["database:read"] }
// Avoid: Overly broad access
{ "scopes": ["*"] }

Set reasonable expiration for security:

{
"name": "Temporary Key",
"scopes": ["database:read"],
"expiresAt": "2024-03-01T00:00:00Z"
}

Use different keys for development and production:

  • dev-backend-key - Development access
  • staging-backend-key - Staging access
  • prod-backend-key - Production access
  • Create a new key before the old one expires
  • Update your application with the new key
  • Revoke the old key

StatusDescription
ActiveKey is valid and working
ExpiredKey has passed its expiration date
RevokedKey has been manually revoked