Skip to content

Conversation

wobsoriano
Copy link
Member

@wobsoriano wobsoriano commented Oct 9, 2025

Description

This PR adds API keys list method to the backend SDK client

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features

    • Backend SDK now supports listing API keys, with filtering by user or organization.
    • Supports pagination for large result sets.
    • Optional flag to include invalid/revoked keys in results.
  • Documentation

    • Clarified the description for the API key creation parameter.

Copy link

changeset-bot bot commented Oct 9, 2025

🦋 Changeset detected

Latest commit: 9201009

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@clerk/backend Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Oct 9, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Oct 9, 2025 4:18am

Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

Walkthrough

Adds a changeset patch entry for @clerk/backend and implements an API keys list capability in the backend SDK: new pagination params type, a list method in APIKeysAPI that GETs /api_keys, and a minor doc tweak to CreateAPIKeyParams.description.

Changes

Cohort / File(s) Summary of Changes
Release Notes / Changeset
\.changeset/mighty-kids-joke.md
Adds a patch changeset describing a new public API: API keys list method in BackendSdkClient.
Backend API Keys Endpoint
packages/backend/src/api/endpoints/APIKeysApi.ts
Introduces GetAPIKeyListParams (ClerkPaginationRequest with subject, includeInvalid), adds APIKeysAPI.list(queryParams) to GET /api_keys returning APIKey[], updates a description string for CreateAPIKeyParams, imports ClerkPaginationRequest from @clerk/types.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor DevApp as Developer App
  participant SDK as BackendSdkClient
  participant APIKeys as APIKeysAPI
  participant HTTP as HTTP Client
  participant Clerk as Clerk API

  DevApp->>SDK: listAPIKeys({ subject, includeInvalid?, pagination... })
  SDK->>APIKeys: list(queryParams)
  APIKeys->>HTTP: GET /api_keys?subject=...&include_invalid=...&limit=...&offset=...
  HTTP->>Clerk: Request
  Clerk-->>HTTP: 200 OK (APIKey[])
  HTTP-->>APIKeys: APIKey[]
  APIKeys-->>SDK: APIKey[]
  SDK-->>DevApp: APIKey[]

  note over DevApp,APIKeys: subject (required), includeInvalid (optional)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

Poem

I thump my paws—new lists, hooray!
Keys hop back in tidy array.
With subject clear and pages neat,
I sniff the endpoints, sweet discrete.
One GET, a nibble, results cascade—
Patch note penned, a burrow upgrade! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the primary change in this pull request by stating that the backend package gains an API keys list method, aligning perfectly with the actual code additions and following conventional commit style.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rob/api-keys-list

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

pkg-pr-new bot commented Oct 9, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6948

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6948

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6948

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6948

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6948

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6948

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6948

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6948

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6948

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6948

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6948

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6948

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6948

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6948

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6948

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6948

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6948

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6948

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6948

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6948

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6948

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6948

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6948

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6948

commit: 9201009

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4910194 and 9201009.

📒 Files selected for processing (2)
  • .changeset/mighty-kids-joke.md (1 hunks)
  • packages/backend/src/api/endpoints/APIKeysApi.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/backend/src/api/endpoints/APIKeysApi.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/backend/src/api/endpoints/APIKeysApi.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/backend/src/api/endpoints/APIKeysApi.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/backend/src/api/endpoints/APIKeysApi.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/backend/src/api/endpoints/APIKeysApi.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/backend/src/api/endpoints/APIKeysApi.ts
.changeset/**

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/mighty-kids-joke.md
🧬 Code graph analysis (1)
packages/backend/src/api/endpoints/APIKeysApi.ts (3)
packages/types/src/pagination.ts (1)
  • ClerkPaginationRequest (5-14)
packages/types/src/clerk.ts (1)
  • CreateAPIKeyParams (1882-1888)
packages/backend/src/api/resources/APIKey.ts (1)
  • APIKey (3-43)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (28)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (tanstack-react-router, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: Static analysis
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (4)
packages/backend/src/api/endpoints/APIKeysApi.ts (3)

1-1: LGTM!

Type-only import follows best practices for tree-shaking and is properly used in the new GetAPIKeyListParams type.


9-20: LGTM!

The type definition is well-structured with clear JSDoc documentation. The use of ClerkPaginationRequest as a base type provides consistent pagination behavior across the SDK.


29-29: LGTM!

The documentation wording is clearer and more actionable.

.changeset/mighty-kids-joke.md (1)

1-5: LGTM!

The changeset correctly documents this as a patch-level change to @clerk/backend. The description accurately reflects the addition of the API keys list method.

Comment on lines +54 to +60
async list(queryParams: GetAPIKeyListParams) {
return this.request<APIKey[]>({
method: 'GET',
path: basePath,
queryParams,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Add explicit return type, JSDoc documentation, and parameter validation.

The method has several issues that should be addressed:

  1. Missing explicit return type: Per coding guidelines, public APIs must have explicit return types for clarity and type safety.
  2. Missing JSDoc documentation: Per coding guidelines, all public APIs must be documented with JSDoc comments.
  3. Missing parameter validation: The subject parameter is required but not validated. Other methods in this class (e.g., revoke, getSecret) validate ID parameters using this.requireId().

Apply this diff to add return type, JSDoc, and validation:

+  /**
+   * List API keys for a user or organization
+   * 
+   * @param queryParams - Query parameters including subject, pagination, and filter options
+   * @returns Promise resolving to an array of APIKey objects
+   */
-  async list(queryParams: GetAPIKeyListParams) {
+  async list(queryParams: GetAPIKeyListParams): Promise<APIKey[]> {
+    this.requireId(queryParams.subject);
+
     return this.request<APIKey[]>({
       method: 'GET',
       path: basePath,
       queryParams,
     });
   }

Additionally, verify whether the API response includes pagination metadata (total count, hasMore, etc.) or just returns an array:


🏁 Script executed:

#!/bin/bash
# Description: Check how other list methods in the API handle pagination responses

# Search for other list methods to understand the pagination pattern
ast-grep --pattern $'async list($$$) {
  $$$
  return this.request$$$
}'

# Also check if there are pagination response types defined
rg -nP --type=ts 'Paginated|PaginationResponse|ListResponse' -C3

Length of output: 99058


🏁 Script executed:

#!/bin/bash
rg -nP --type=ts 'GetAPIKeyListParams\b' -C3 packages/backend/src/api

Length of output: 1054


Use paginated response type and validate subject ID

  • Validate the required subject via this.requireId(queryParams.subject) before calling the API.
  • Change the signature to
    async list(queryParams: GetAPIKeyListParams): Promise<PaginatedResourceResponse<APIKey[]>>
    and update the request generic to PaginatedResourceResponse<APIKey[]>.
🤖 Prompt for AI Agents
In packages/backend/src/api/endpoints/APIKeysApi.ts around lines 54 to 60, the
list method must validate the required subject ID and return a paginated
response type: call this.requireId(queryParams.subject) at the top of the method
to validate the subject, change the method signature to async list(queryParams:
GetAPIKeyListParams): Promise<PaginatedResourceResponse<APIKey[]>> and update
the this.request generic to PaginatedResourceResponse<APIKey[]> so the API call
returns the paginated shape.

@wobsoriano wobsoriano enabled auto-merge (squash) October 9, 2025 14:58
@wobsoriano wobsoriano merged commit 56a81aa into main Oct 9, 2025
43 checks passed
@wobsoriano wobsoriano deleted the rob/api-keys-list branch October 9, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants