CosmicAC Logo

API Key Management

API key generation, storage, validation, and lifecycle management for authenticating with CosmicAC services. API keys authorize requests to your inference endpoints and track usage.


Key Format

API keys use the following format:

ttr-proj-<base64_encoded_36_random_bytes>

Example

ttr-proj-a8F3kL9mNpQrStUvWxYz1234567890abcdef

Capabilities

The API key system supports the following capabilities:

CapabilityDescription
Dual StorageStores keys in local SQLite and distributed HyperDB/Autobase
SecurityHashes keys with HMAC-SHA256 using configurable secrets
Lifecycle OperationsCreate, validate, revoke (soft delete), update
Rate LimitingLimits key creation to 5 keys per minute per user

Key Storage Schema

FieldTypeDescription
apiKeyIdstringUnique identifier (key_<hex>)
apiKeystringHMAC-SHA256 hashed value
projectIdstringAssociated project UUID
userIdstringOwner user ID
statusenumactive or revoked
createdAttimestampKey creation time
expiryAttimestampKey creation time
lastUsedAttimestampLast usage time
revokedAttimestampRevocation time (if revoked)

Object Structure

{
  "apiKeyId": "key_<hex>",
  "apiKey": "hashed_value",
  "projectId": "project_uuid",
  "userId": "user_id",
  "status": "active|revoked",
  "createdAt": "timestamp",
  "expiryAt": "timestamp",
  "lastUsedAt": "timestamp",
  "revokedAt": "timestamp"
}

Usage Logging Schema

FieldTypeDescription
idstringUnique identifier (key_<hex>)
apiKeyIdstringAssociated key ID
projectIdstringAssociated project UUID
userIdstringOwner user ID
timestampintegerUnix timestamp
datestringKey creation time
hourintegerHour of day (0-23)
tokensInintegerInput tokens consumed
tokensOutintegerOutput tokens generated
requestsintegerNumber of requests

Object Structure

{
  "id": "usage_<hex>",
  "apiKeyId": "key_<hex>",
  "projectId": "project_uuid",
  "userId": "user_id",
  "timestamp": 1704067200,
  "date": "2025-01-01",
  "hour": 14,
  "tokensIn": 150,
  "tokensOut": 320,
  "requests": 1
}

Key Status Values

StatusDescription
activeThe key is valid and can be used for authentication.
revokedThe key is soft-deleted and rejected on validation.

On this page