Skip to content

User Profile

Self-service endpoints for authenticated users to view their profile, API keys, usage statistics, and rotate keys. All endpoints require a Bearer token obtained via POST /api/auth/login.

Get Current User

GET /api/me

Authentication

Bearer token in Authorization header.

Success Response

{
	"userId": "user-123",
	"email": "alice@example.com",
	"name": "Alice",
	"role": "user",
	"status": 1,
	"createdAt": "2025-01-15T10:00:00.000Z",
	"updatedAt": "2025-01-15T10:00:00.000Z",
	"lastLogin": "2025-06-01T14:30:00.000Z"
}

Error Responses

StatusCodeDescription
401-Missing or invalid Bearer token
404-User not found

Get User Keys

GET /api/me/keys

Returns the authenticated user’s API key metadata. The full key value is never returned — only a suffix for identification.

Success Response

{
	"data": [
		{
			"uid": { "type": "UserKey", "id": "key-user-123" },
			"attrs": { ... },
			"apiKey": null,
			"keySuffix": "-----",
			"currentDailySpend": 12.50,
			"currentMonthlySpend": 85.00,
			"lastDailyReset": "2025-06-01T00:00:00.000Z",
			"lastMonthlyReset": "2025-06-01T00:00:00.000Z"
		}
	]
}
FieldDescription
apiKeyAlways null — full key is never returned
keySuffixLast characters of key hash for identification
currentDailySpendSpend accumulated since last daily reset
currentMonthlySpendSpend accumulated since last monthly reset

Get Usage Statistics

GET /api/me/usage

Returns aggregated usage statistics for the authenticated user.

Success Response

{
	"currentDailySpend": 12.50,
	"dailySpendLimit": 0,
	"currentMonthlySpend": 85.00,
	"monthlySpendLimit": 0,
	"totalRequests": 1547,
	"totalTokens": 2340000,
	"lastDailyReset": "2025-06-01T00:00:00.000Z",
	"lastMonthlyReset": "2025-06-01T00:00:00.000Z"
}
FieldDescription
currentDailySpendCost accumulated today
dailySpendLimitDaily spend cap (0 = unlimited)
currentMonthlySpendCost accumulated this month
monthlySpendLimitMonthly spend cap (0 = unlimited)
totalRequestsTotal permitted requests across all time
totalTokensTotal tokens consumed across all time

Rotate API Key

POST /api/me/rotate

Generates a new API key for the authenticated user and revokes the existing one. The new key is returned once — store it immediately.

Success Response

{
	"apiKey": "ziri-user-123-a1b2c3d4e5f67890",
	"userId": "user-123",
	"message": "Key rotated. Save the new key — you won't see it again."
}

Error Responses

StatusCodeDescription
401-Missing or invalid Bearer token
404-User not found or no existing key to rotate