Skip to content

fix: migrate management keys to private REST API - #7

Merged
erikchi merged 1 commit into
mainfrom
erikchi/fix-management-keys-rest
Aug 26, 2026
Merged

fix: migrate management keys to private REST API#7
erikchi merged 1 commit into
mainfrom
erikchi/fix-management-keys-rest

Conversation

@erikchi

@erikchi erikchi commented Aug 26, 2026

Copy link
Copy Markdown
Member

Symptom

Registration still failing after #6:

{"reason":"management_key_create_failed",
 "error_detail":"could not get create action hash, available: map[]"}

#6 migrated account state; the provisioning-key lifecycle was still on the server actions OpenRouter removed. This is the remaining half.

Endpoints

Derived from the authenticated bundle — module 677420, hooks useCreateManagementApiKey / useDeleteWorkspaceApiKey:

op call
list GET /api/frontend/v1/private/management-keys?page=N
create POST /api/frontend/v1/private/workspace-api-keys/management
delete PATCH /api/frontend/v1/private/workspace-api-keys/{hash}

Delete body:

{"payload":{"deleted":true},"opts":{"is_provisioning_key":true}}

That opts flag is required and must be snake_case — the endpoint answers 403 for opts:{} and for opts:{"isProvisioningKey":true}. It corresponds to the third argument the old server action passed ({"isProvisioningKey":true}), which is how it was found.

Listing now paginates — a correctness fix beyond the migration

The legacy path scraped the settings page and only ever saw the first 20 keys. CleanupProvisioningKeys deletes keys whose name matches a station label, so on a busy account it was silently leaving keys alive and under-reporting the count. The test account holds 164 management keys; the old path could see roughly 20 of them.

Verification

End-to-end against a live account through the exported Go API (not curl), with action hashes: map[] throughout — proving none of it touches the removed actions:

listed 164 keys              ← pagination working
created key sk-or-v1-...
probe key found by label, total now 165
cleanup deleted 1 key(s)
final count back to 164      ← test asserts no drift

The probe key is created under a dedicated label and removed via CleanupProvisioningKeys, so the live test leaves the account exactly as it found it — and it exercises the label-matching cleanup path rather than just the raw delete.

Unit tests cover the list envelope, total_count, hashless entries (which would give cleanup an undeletable target), error/HTML bodies, and the empty page that terminates pagination.

All three exported functions try REST first and keep the legacy server-action path as a fallback, consistent with FetchActivityData in #6.

🤖 Generated with Claude Code

Registration was still failing with `management_key_create_failed` /
`could not get create action hash, available: map[]`. The previous commit
migrated account state; the provisioning-key lifecycle was still on the
server actions OpenRouter removed.

Endpoints derived from the authenticated bundle (module 677420, hooks
useCreateManagementApiKey / useDeleteWorkspaceApiKey):

  list   GET   /api/frontend/v1/private/management-keys?page=N
  create POST  /api/frontend/v1/private/workspace-api-keys/management
  delete PATCH /api/frontend/v1/private/workspace-api-keys/{hash}
               {"payload":{"deleted":true},"opts":{"is_provisioning_key":true}}

The delete opts flag is required and must be snake_case: the endpoint answers
403 for opts:{} and for opts:{"isProvisioningKey":true}, matching the third
argument the old server action passed.

Listing now paginates. This is a correctness fix beyond the migration: the
legacy path scraped the settings page and only ever saw the first 20 keys, so
CleanupProvisioningKeys silently under-reported on busy accounts. The test
account holds 164 management keys, of which the old path could see ~20.

All three exported functions try REST first and keep the legacy server-action
path as a fallback, consistent with FetchActivityData.

Verified end-to-end against a live account through the exported Go API, with
`action hashes: map[]` throughout: listed 164 keys (proving pagination),
created a key, found it by label, deleted it via CleanupProvisioningKeys, and
confirmed the count returned to 164 -- the probe left no residue.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@erikchi
erikchi merged commit 50edbae into main Aug 26, 2026
2 checks passed
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