API Keys Management
API Keys Management
Section titled “API Keys Management”Manage Management API Keys using JWT authentication. These APIs allow you to create, list, update, delete, revoke, and restore API Keys.
Authentication
Section titled “Authentication”JWT authentication is required for all API Key management operations.
Authorization: Bearer <access_token>Content-Type: application/jsonCreate API Key
Section titled “Create API Key”Create a new Management API Key.
Request
Section titled “Request”POST /management/api-keysRequest Body
Section titled “Request Body”{ "org_id": "0", "name": "finance-dashboard", "description": "Used for finance dashboard queries", "expires_at": 0, "scopes": ["balance:read", "usage:read"]}Field Descriptions
Section titled “Field Descriptions”| Field | Type | Required | Description |
|---|---|---|---|
org_id | string | No | Organization ID. For personal scope, omit it or use the default value |
name | string | Yes | Name, 1 to 100 characters |
description | string | No | Description, up to 500 characters |
expires_at | int64 | No | Unix timestamp. 0 means never expires |
scopes | string[] | No | Scope list. Request validation limits each item to 1 to 50 characters; logic currently allows up to 10 items |
- If
expires_atis greater than0, it must be later than the current time. - The same user can create at most 10
activekeys within the same organization. - The full
api_keyis returned only once when creation succeeds. Save it immediately.
Response Example
Section titled “Response Example”{ "meta": { "code": 0, "message": "success", "request_id": "xxx" }, "data": { "api_key": "sk_mg_xxx", "id": "4e5f2a15-b9a1-498d-8c3e-f7f2608a1111", "org_id": "0", "name": "finance-dashboard", "description": "Used for finance dashboard queries", "status": "active", "display": "sk_mg_a1b2c3d4...5678abcd", "last_used_at": 0, "expires_at": 0, "created_at": 1710000000, "scopes": ["balance:read", "usage:read"] }}Request Examples
Section titled “Request Examples”curl -X POST 'https://portal-api.r9s.ai/api/v1/portal/management/api-keys' \ -H 'Authorization: Bearer <access_token>' \ -H 'Content-Type: application/json' \ -d '{ "name": "finance-dashboard", "description": "Used for finance dashboard queries", "expires_at": 0, "scopes": ["balance:read", "usage:read"] }'List API Keys
Section titled “List API Keys”List all Management API Keys for the authenticated user.
Request
Section titled “Request”GET /management/api-keysQuery Parameters
Section titled “Query Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
status | string | No | Allowed values: active, disabled, revoked |
page | int | No | Default is 1 |
per_page | int | No | Default is 20, maximum is 100 |
Response Example
Section titled “Response Example”{ "meta": { "code": 0, "message": "success", "request_id": "xxx" }, "data": { "list": [ { "id": "4e5f2a15-b9a1-498d-8c3e-f7f2608a1111", "org_id": "0", "name": "finance-dashboard", "description": "Used for finance dashboard queries", "status": "active", "display": "sk_mg_a1b2c3d4...5678abcd", "last_used_at": 0, "expires_at": 0, "created_at": 1710000000, "scopes": ["balance:read", "usage:read"] } ], "total": 1 }}Request Examples
Section titled “Request Examples”curl -X GET 'https://portal-api.r9s.ai/api/v1/portal/management/api-keys?status=active&page=1&per_page=20' \ -H 'Authorization: Bearer <access_token>'Update API Key
Section titled “Update API Key”Update an existing Management API Key.
Request
Section titled “Request”PUT /management/api-keys/:api_key_idRequest Body
Section titled “Request Body”{ "name": "finance-dashboard-prod", "description": "Production finance dashboard"}- Only
nameanddescriptioncan currently be updated.
Request Examples
Section titled “Request Examples”curl -X PUT 'https://portal-api.r9s.ai/api/v1/portal/management/api-keys/4e5f2a15-b9a1-498d-8c3e-f7f2608a1111' \ -H 'Authorization: Bearer <access_token>' \ -H 'Content-Type: application/json' \ -d '{ "name": "finance-dashboard-prod", "description": "Production finance dashboard" }'Delete API Key
Section titled “Delete API Key”Delete a Management API Key.
Request
Section titled “Request”DELETE /management/api-keys/:api_key_id- Deletion is a soft delete.
Request Examples
Section titled “Request Examples”curl -X DELETE 'https://portal-api.r9s.ai/api/v1/portal/management/api-keys/4e5f2a15-b9a1-498d-8c3e-f7f2608a1111' \ -H 'Authorization: Bearer <access_token>'Revoke API Key
Section titled “Revoke API Key”Revoke a Management API Key.
Request
Section titled “Request”POST /management/api-keys/revokeRequest Body
Section titled “Request Body”{ "api_key_id": "4e5f2a15-b9a1-498d-8c3e-f7f2608a1111"}- Only keys owned by the current user can be revoked.
- A revoked key will return an unauthorized error if used again for query APIs.
Request Examples
Section titled “Request Examples”curl -X POST 'https://portal-api.r9s.ai/api/v1/portal/management/api-keys/revoke' \ -H 'Authorization: Bearer <access_token>' \ -H 'Content-Type: application/json' \ -d '{ "api_key_id": "4e5f2a15-b9a1-498d-8c3e-f7f2608a1111" }'Restore API Key
Section titled “Restore API Key”Restore a revoked Management API Key.
Request
Section titled “Request”POST /management/api-keys/restoreRequest Body
Section titled “Request Body”{ "api_key_id": "4e5f2a15-b9a1-498d-8c3e-f7f2608a1111"}- Only keys in
revokedstatus can be restored toactive.
Request Examples
Section titled “Request Examples”curl -X POST 'https://portal-api.r9s.ai/api/v1/portal/management/api-keys/restore' \ -H 'Authorization: Bearer <access_token>' \ -H 'Content-Type: application/json' \ -d '{ "api_key_id": "4e5f2a15-b9a1-498d-8c3e-f7f2608a1111" }'Status Definitions
Section titled “Status Definitions”| Status | Description |
|---|---|
active | Available for normal use |
disabled | Currently unavailable |
revoked | Revoked and no longer usable for query APIs |
- The currently exposed APIs support revoke and restore operations.
- The
disabledstatus exists in listing and verification logic, but there is currently no user-facing API to set a key todisabled.
Common Errors
Section titled “Common Errors”| Scenario | Typical Error |
|---|---|
| Missing authentication info | unauthorized |
| Authorization header is not in Bearer format | unauthorized: invalid authorization format |
| Invalid API Key format | i18n error corresponding to invalid_format |
| API Key is revoked or expired | returns 401 |
Missing api_key_id | api_key_id is required |
| Non-admin attempts to create an organization-level key | permission denied |