Skip to content

API Keys Management

Manage Management API Keys using JWT authentication. These APIs allow you to create, list, update, delete, revoke, and restore API Keys.

JWT authentication is required for all API Key management operations.

Authorization: Bearer <access_token>
Content-Type: application/json

Create a new Management API Key.

POST /management/api-keys
{
"org_id": "0",
"name": "finance-dashboard",
"description": "Used for finance dashboard queries",
"expires_at": 0,
"scopes": ["balance:read", "usage:read"]
}
FieldTypeRequiredDescription
org_idstringNoOrganization ID. For personal scope, omit it or use the default value
namestringYesName, 1 to 100 characters
descriptionstringNoDescription, up to 500 characters
expires_atint64NoUnix timestamp. 0 means never expires
scopesstring[]NoScope list. Request validation limits each item to 1 to 50 characters; logic currently allows up to 10 items
  • If expires_at is greater than 0, it must be later than the current time.
  • The same user can create at most 10 active keys within the same organization.
  • The full api_key is returned only once when creation succeeds. Save it immediately.
{
"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"]
}
}
Terminal window
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 all Management API Keys for the authenticated user.

GET /management/api-keys
ParameterTypeRequiredDescription
statusstringNoAllowed values: active, disabled, revoked
pageintNoDefault is 1
per_pageintNoDefault is 20, maximum is 100
{
"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
}
}
Terminal window
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 an existing Management API Key.

PUT /management/api-keys/:api_key_id
{
"name": "finance-dashboard-prod",
"description": "Production finance dashboard"
}
  • Only name and description can currently be updated.
Terminal window
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 a Management API Key.

DELETE /management/api-keys/:api_key_id
  • Deletion is a soft delete.
Terminal window
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 a Management API Key.

POST /management/api-keys/revoke
{
"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.
Terminal window
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 a revoked Management API Key.

POST /management/api-keys/restore
{
"api_key_id": "4e5f2a15-b9a1-498d-8c3e-f7f2608a1111"
}
  • Only keys in revoked status can be restored to active.
Terminal window
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"
}'
StatusDescription
activeAvailable for normal use
disabledCurrently unavailable
revokedRevoked and no longer usable for query APIs
  • The currently exposed APIs support revoke and restore operations.
  • The disabled status exists in listing and verification logic, but there is currently no user-facing API to set a key to disabled.
ScenarioTypical Error
Missing authentication infounauthorized
Authorization header is not in Bearer formatunauthorized: invalid authorization format
Invalid API Key formati18n error corresponding to invalid_format
API Key is revoked or expiredreturns 401
Missing api_key_idapi_key_id is required
Non-admin attempts to create an organization-level keypermission denied
  • Overview - Manager API overview and authentication
  • Balance - Query account balance
  • Usage - Query usage details