Skip to content

feat(dashboard): update key ratelimits through api sdk#6594

Open
chronark wants to merge 2 commits into
chronark/dashboard-sdk-update-key-external-idfrom
chronark/dashboard-sdk-update-key-ratelimits
Open

feat(dashboard): update key ratelimits through api sdk#6594
chronark wants to merge 2 commits into
chronark/dashboard-sdk-update-key-external-idfrom
chronark/dashboard-sdk-update-key-ratelimits

Conversation

@chronark

@chronark chronark commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • Routes dashboard key ratelimit edits through the public API SDK via keys.updateKey
  • Maps form ratelimit rules to the SDK ratelimits payload
  • Sends an empty ratelimits array when limits are disabled so the API clears existing rules
  • Reuses the shared SDK error-message helper for key ratelimit failures
  • Removes the old key.update.ratelimit tRPC route

Verification

Change ratelimits of a key in the dashboard

@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
dashboard Ready Ready Preview, Comment Jul 1, 2026 8:58am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
design Ignored Ignored Preview Jul 1, 2026 8:58am

Request Review

@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-external-id branch from d13872a to 8ea725b Compare June 30, 2026 12:45
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-ratelimits branch from 52c662c to 68dd16f Compare June 30, 2026 12:45
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-ratelimits branch from 68dd16f to c7aaa95 Compare July 1, 2026 05:54
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-external-id branch from 8ea725b to 2edc891 Compare July 1, 2026 05:54
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-external-id branch from 2edc891 to feff938 Compare July 1, 2026 06:03
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-ratelimits branch from c7aaa95 to 44d7744 Compare July 1, 2026 06:03
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-external-id branch from feff938 to efbfea2 Compare July 1, 2026 06:09
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-ratelimits branch from 44d7744 to 0b536fa Compare July 1, 2026 06:09
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-external-id branch from efbfea2 to f1027eb Compare July 1, 2026 07:27
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-ratelimits branch from 0b536fa to c1ed212 Compare July 1, 2026 07:27
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-ratelimits branch from c1ed212 to aece5fc Compare July 1, 2026 07:58
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-external-id branch from f1027eb to 111e7bc Compare July 1, 2026 07:58
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-ratelimits branch from aece5fc to 7bc26e1 Compare July 1, 2026 08:06
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-external-id branch from 111e7bc to 15a19e8 Compare July 1, 2026 08:06
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-external-id branch from 15a19e8 to eba63f0 Compare July 1, 2026 08:22
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-ratelimits branch from 7bc26e1 to 157d68a Compare July 1, 2026 08:22
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-external-id branch from eba63f0 to d43d518 Compare July 1, 2026 08:32
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-ratelimits branch from 157d68a to 717dfbc Compare July 1, 2026 08:32
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-external-id branch from d43d518 to 6c91d58 Compare July 1, 2026 08:46
@chronark chronark force-pushed the chronark/dashboard-sdk-update-key-ratelimits branch from 717dfbc to 5e84776 Compare July 1, 2026 08:46
@chronark chronark marked this pull request as ready for review July 1, 2026 08:55

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — routes dashboard key ratelimit edits through the public API SDK (keys.updateKey), replacing the bespoke tRPC route, following the same pattern already used for credits, external-id, metadata, and expiration.

  • Migrate useEditKeyRatelimits to the SDKhooks/use-edit-ratelimits.ts now calls getUnkeyClient().keys.updateKey({ keyId, ratelimits }) via a plain useMutation, mapping form rules to { name, limit, duration: rule.refillInterval, autoApply }.
  • Clear on disable — sends an empty (non-nil) ratelimits: [] when limits are disabled, which the v2 handler treats as "delete all existing rules."
  • Toast/cache wiringonSuccess reads variables.keyId (was data.keyId) and invalidates trpcUtils.api.keys.list; onError uses the shared getErrorMessage helper.
  • Remove legacy route — deletes lib/trpc/routers/key/updateRatelimit.ts and its key.update.ratelimit registration in routers/index.ts.
  • Comment renameedit-ratelimits/index.tsx comment updated useEditRatelimitsuseEditKeyRatelimits.

I verified the load-bearing API contract against svc/api/routes/v2_keys_update_key/handler.go: ratelimit reconciliation is gated on req.Ratelimits != nil and keyed by name, so an empty non-nil array clears all rules (disabled path) and a populated array performs a full delete-missing + upsert (enabled path) — matching the old tRPC behavior. The mapped field names and types line up with the SDK RatelimitRequest schema.

Two non-blocking observations, both inherited from the broader SDK-migration effort rather than introduced here:

  • The v2 API reconciles ratelimits by name, so renaming a rule is a delete + recreate (the row id and created timestamp reset). This differs from the old id-keyed tRPC path but is how every v2 client behaves.
  • The removed tRPC route emitted a ratelimit.update audit event with per-rule metadata; the v2 handler's ratelimit block emits no ratelimit-specific audit event. This granular audit trail is lost — consistent with the credits/external-id migrations, so likely intentional, but worth confirming that dropping the per-rule audit detail is acceptable.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using Claude Opus𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant