Skip to main content
POST
/
api
/
v1
/
api-keys
Create API key
import requests

url = "https://api.example.com/api/v1/api-keys"

payload = {
    "name": "<string>",
    "principal_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
    "scopes": ["<string>"],
    "expires_at": "2023-11-07T05:31:56Z"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
{
  "result": {
    "api_key": {
      "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
      "principal_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
      "name": "<string>",
      "key_prefix": "<string>",
      "scopes": [
        "<string>"
      ],
      "expires_at": "2023-11-07T05:31:56Z",
      "last_used_at": "2023-11-07T05:31:56Z",
      "is_revoked": true,
      "revoked_at": "2023-11-07T05:31:56Z",
      "created_at": "2023-11-07T05:31:56Z",
      "updated_at": "2023-11-07T05:31:56Z",
      "delegation_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
      "pact_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
    },
    "raw_key": "<string>"
  },
  "success": true,
  "suggestion": "",
  "message": "",
  "meta": {
    "total": 123,
    "offset": 123,
    "limit": 123,
    "has_more": true,
    "after": "<string>",
    "before": "<string>"
  }
}

Headers

X-API-Key
string | null
X-Assistant-Service-Key
string | null

Body

application/json

Request payload for creating an API key.

name
string
required

The display name for this API key. Max 255 characters.

Maximum string length: 255
principal_id
string<uuid> | null

The ID of the principal to create the API key for. Required when using service credential authentication; ignored when using principal API key authentication.

scopes
string[]

The access scopes for this key. Use ["*"] for full access, or restrict with resource:action format (for example, ["wallet:read", "wallet:write"]). Possible actions: read, write, status.

expires_at
string<date-time> | null

The expiry timestamp for this key, in ISO 8601 format. If omitted, the key does not expire.

Response

Already exists (idempotent). Successful Response

result
ApiKeyCreateResult · object
required

Create API key result including one-time plaintext key.

success
boolean
default:true
suggestion
string
default:""
message
string
default:""
meta
PaginationMeta · object

Pagination metadata for list responses.

Supports both legacy offset-based and cursor-based pagination. Cursor fields (has_more, after, before) are populated for cursor-paginated endpoints. Legacy fields (offset, limit) are populated when the caller uses the deprecated offset parameter.