Get API key

Key management API

View as Markdown

Create, list and revoke your members' API keys and your org's application keys from a script.

The key management API lets an org admin create, list and revoke API keys from a script. Use it for members' keys, for example when someone joins, sets up a new machine or leaves. It also handles the org's application keys, which belong to the org and run robots and services. It is at https://privatemind.com/api/v1/api-keys and https://privatemind.com/api/v1/application-keys, not on api.privatemind.com, which serves the inference API.

Management keys

The API takes a management key, which an org admin creates at Settings → Org → Management Keys (/settings/org/management-keys). A management key:

  • belongs to the admin who created it, and works only while they are an org admin of this org
  • expires after 30 days to a year (90 days by default), and each admin can hold five at once
  • can call this API and the Kubernetes API and nothing else: the inference API and every other application route answer it with 403

Any org admin can revoke any of the org's management keys from the same page. A revoked key stops working within a minute, and keys it already created keep working.

Send it as a bearer token, exactly as it was shown when you created it:

Text
Authorization: Bearer <ACCESS_KEY_ID>:<SECRET>

Keys created for members

A key you create through this API is an ordinary API key belonging to the member, with two differences.

  • It can only call models: /v1/chat/completions, /v1/messages, their count_tokens routes, /v1/models, /v1/opencode.json and /v1/responses. Files, batches, embeddings, images, audio and the key management API itself answer it with 403.
  • It records which admin created it. The member sees it on their own API keys page with that admin's email on it, and can revoke it like any of their keys.

It counts toward the member's limit of five active keys, and its spend rolls up to the member like any other key's. Its rate limit and budget must fit your org's limits for keys. If you leave out the rate limit or in-flight limit, the key takes your org's defaults for new keys, which PrivateMind sets for your org on request. To point a coding agent at the key, see Coding agents.

Create a key

cURL
curl -s -X POST https://privatemind.com/api/v1/api-keys \
  -H "Authorization: Bearer $PM_MANAGEMENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"email": "new.hire@example.com", "name": "laptop", "expires_in_days": 90}'
Field Type Meaning
user_id or email integer or string A member of your org below your role. Leave both out to create a key for yourself. Email matching ignores case.
name string, 3 to 100 characters The key's name in tables and logs.
expires_in_days integer, 1 to 365 Default 90.
rate_limit_rpm integer Requests per minute. Defaults to your org's default for new keys, or 60 if it has none.
max_in_flight_tokens integer The most tokens the key can have in flight at once, counting each request's prompt and the reply it may write. A request that would go over is refused with 429 and can be retried. Defaults to your org's in-flight limit, which you can lower for a key but not raise.
budget_usd number Optional spend cap for this key.

Any other field is refused with 400, so a misspelt field cannot quietly create a key that behaves differently.

The API answers 201 with the key, and the full credential in key. This is the only time you see it, so store it straight away.

JSON
{
  "data": {
    "id": "0f8c1c1e-1111-4222-8333-444455556666",
    "access_key_id": "sk-pm-by5EuiQ7wPzT8mLx2cVn4dRa",
    "prefix": "sk-pm-by5Eui...",
    "name": "laptop",
    "user_id": 2900,
    "email": "new.hire@example.com",
    "status": "active",
    "scopes": ["inference:completions"],
    "rate_limit_rpm": 60,
    "max_in_flight_tokens": null,
    "budget_usd": null,
    "spent_usd": 0,
    "created_at": "2026-10-07T10:00:00Z",
    "expires_at": "2027-01-05T10:00:00Z",
    "created_by": { "user_id": 2865, "email": "admin@example.com" },
    "key": "sk-pm-by5EuiQ7wPzT8mLx2cVn4dRa:<secret>"
  }
}

List keys

GET /api/v1/api-keys returns your org's API keys, newest first. Keys belong to members, so this includes keys members created themselves.

Param Meaning
status active (default), or all to include revoked and expired keys.
user_id or email One person's keys, including someone who has since left the org.
limit Page size, 1 to 500. Default 100.
page From 1.
JSON
{
  "data": [ { "id": "...", "name": "laptop", "status": "active", "...": "..." } ],
  "pagination": { "page": 1, "limit": 100, "total": 1, "has_more": false }
}

Keys in a list never carry key. status is one of active, expired, revoked or inactive. max_in_flight_tokens is null when the key follows your org's in-flight limit.

Read a key

GET /api/v1/api-keys/{id} returns { "data": <key> }, or 404 when the id is not a key of your org.

Revoke a key

DELETE /api/v1/api-keys/{id} revokes the key and returns it with status: "revoked". It stops working within a minute. Revoking a key that is already revoked changes nothing.

You can revoke your own keys, those of members below your role, and those of people who have left the org. Another org admin's keys are theirs to revoke.

Application keys

An application key belongs to your org and to no one person. Use one per robot, pipeline or service. Each is its own account with its own spend and budget. Every robot shows as its own line on the Application Keys page (/settings/org/application-keys), and in the Compliance API's org usage when grouped by user or by API key. A key created through this API can only call models, like a member key, and expires after 1 to 365 days (90 by default). Keys created on the Application Keys page are listed here too and keep the access they were created with.

/api/v1/application-keys takes the same management key and has the same four calls as /api/v1/api-keys, with no member to name.

Create an application key

cURL
curl -s -X POST https://privatemind.com/api/v1/application-keys \
  -H "Authorization: Bearer $PM_MANAGEMENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "nightly eval robot", "expires_in_days": 90}'
Field Type Meaning
name string, 3 to 100 characters The key's name in tables and logs.
expires_in_days integer, 1 to 365 Default 90.
rate_limit_rpm integer Requests per minute. Defaults to your org's default for new keys, or 600 if it has none.
max_in_flight_tokens integer As for member keys: defaults to your org's in-flight limit, which you can lower for a key but not raise.
budget_usd number Optional spend cap for this key; 0 blocks it. Without one, the key has your org's default budget to itself.

user_id, email and any other field are refused with 400.

The API answers 201 with the key and the full credential in key, shown only this once. An application key has no user_id or email; otherwise it has the same fields as a member key.

JSON
{
  "data": {
    "id": "6d0b8f6a-2b1e-4f6c-9a43-0c7f1e2d3b4a",
    "access_key_id": "PMINDAPPQ7WPZT8MLX2CVN4DRA3K5H6J",
    "prefix": "sk-pm-org",
    "name": "nightly eval robot",
    "status": "active",
    "scopes": ["inference:completions"],
    "rate_limit_rpm": 600,
    "max_in_flight_tokens": null,
    "budget_usd": null,
    "spent_usd": 0,
    "created_at": "2026-10-08T10:00:00Z",
    "expires_at": "2027-01-06T10:00:00Z",
    "created_by": { "user_id": 2865, "email": "admin@example.com" },
    "key": "PMINDAPPQ7WPZT8MLX2CVN4DRA3K5H6J:<secret>"
  }
}

List, read and revoke application keys

  • GET /api/v1/application-keys lists your org's application keys, newest first, with status, limit and page as for member keys.
  • GET /api/v1/application-keys/{id} returns one, or 404.
  • DELETE /api/v1/application-keys/{id} revokes it. It stops working within a minute. Any org admin can revoke any of the org's application keys, whoever created it.

Short-lived tokens that PrivateMind creates for workspaces, notebooks, jobs and coding agents are not application keys in this sense, and this API neither lists nor revokes them.

Errors

Errors from the API itself have the shape { "error": { "type": "...", "message": "..." } }.

Status type When
400 invalid_request_error A missing, malformed or unknown field, or a value over your org's limits for keys.
403 permission_error Not a management key, a management key of another org, or a member at or above your role.
404 not_found_error No such member or key in your org.
409 key_limit_reached The member already has five active keys.
409 conflict_error More than one member has that email. Use user_id.
429 Over the management key's 60 requests per minute.

A missing, invalid, expired or revoked key answers 401, and a management key whose owner is no longer an org admin answers 404. Both use the application's general shape, { "success": false, "message": "..." }.

Every key created or revoked through this API is recorded in your org's audit log against the management key, as member_api_key_created or member_api_key_revoked, and for application keys org_application_key_created or org_application_key_revoked.