Skip to main content

keys.list

Lists all active API keys for the authenticated user. This endpoint requires Clerk JWT authentication (used in dashboard).

Authentication

This endpoint uses JWT authentication instead of API key authentication:
Authorization: Bearer <clerk_jwt_token>
This endpoint is primarily used in dashboard applications where users are authenticated via Clerk.

Parameters

No parameters required. Returns all keys for the authenticated user.

Response

Returns an array of API key objects:
id
string
Internal UUID for the API key record
clerkUserId
string
Your Clerk user ID (tenant identifier)
clerkKeyId
string
Clerk’s API key ID
name
string
Descriptive name for the key (e.g., “Production Key”)
lastUsedAt
string | null
ISO 8601 timestamp of last usage, or null if never used
createdAt
string
ISO 8601 timestamp of creation
revokedAt
string | null
ISO 8601 timestamp of revocation, or null if active

Examples

import { trpc } from '@/lib/trpc';

function APIKeysPage() {
  const { data: keys, isLoading } = trpc.keys.list.useQuery();
  
  if (isLoading) return <div>Loading...</div>;
  
  return (
    <div>
      <h2>Your API Keys</h2>
      {keys?.map((key) => (
        <div key={key.id}>
          <h3>{key.name}</h3>
          <p>Created: {new Date(key.createdAt).toLocaleDateString()}</p>
          <p>Last used: {key.lastUsedAt ? new Date(key.lastUsedAt).toLocaleDateString() : 'Never'}</p>
        </div>
      ))}
    </div>
  );
}
[
  {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "clerkUserId": "user_372Icb...",
    "clerkKeyId": "key_2abc123...",
    "name": "Production Key",
    "lastUsedAt": "2024-01-15T10:30:00.000Z",
    "createdAt": "2024-01-01T08:00:00.000Z",
    "revokedAt": null
  },
  {
    "id": "660e8400-e29b-41d4-a716-446655440001",
    "clerkUserId": "user_372Icb...",
    "clerkKeyId": "key_3def456...",
    "name": "Development Key",
    "lastUsedAt": "2024-01-14T15:20:00.000Z",
    "createdAt": "2024-01-05T12:00:00.000Z",
    "revokedAt": null
  }
]