---
title: "Create User Api Key"
method: POST
path: "/api/user/api-keys"
tags: ["User"]
---

# Create User Api Key

`POST /api/user/api-keys`

## Request

- Base URL: `https://api.agentstack.tech` (the document declares no server; this is the origin it was published from)
- URL: `https://api.agentstack.tech/api/user/api-keys`
- Auth: one of:
  - API key in header `X-API-Key`
  - HTTP bearer

Create a user or agent PAT (ecosystem identity, project_id=1 in JWT).

## Headers

- `Idempotency-Key` string, nullable

## Request body

- CreateUserAPIKeyRequest
  - `name` string, required: Name for the API key
  - `expires_at` string, nullable: Expiration date (ISO 8601 format)
  - `actor_kind` 'user' | 'agent': user = acts as you; agent = scoped agent
  - `preset` string, nullable: agent_runner | readonly_data | commerce_bot | full_project | user_full
  - `service_caps` string[], nullable: Explicit cap allowlist; overrides preset
  - `resource_scope` ResourceScopeModel
    - `mode` 'all_accessible' | 'projects'
    - `project_ids` integer[]
  - `project_id` integer, nullable: Pin for agent keys when resource_scope omitted
  - `confirm_agent_all_accessible` boolean: Required when actor_kind=agent and resource_scope is all_accessible

## Response `201`

Successful Response

- CreateUserAPIKeyResponse
  - `key_id` string, required
  - `api_key` string, required
  - `name` string, required
  - `created_at` string, required
  - `expires_at` string, nullable, required
  - `status` string, required
  - `actor_kind` string, nullable
  - `resource_scope` object, nullable
  - `service_caps` string[], nullable
  - `preset` string, nullable

## Other responses

- `400`: Bad Request
- `401`: Unauthorized
- `403`: Forbidden
- `404`: Not Found
- `409`: Conflict
- `422`: Validation Error
- `429`: Too Many Requests
- `500`: Internal Server Error

---

[API](https://skmtc.dev/agentstack/apis/agentstack-core-api.md) · [All operations](https://skmtc.dev/agentstack/apis/agentstack-core-api/llms.txt) · [OpenAPI document](https://skmtc.dev/agentstack/apis/agentstack-core-api/revisions/8ecf3406e74a?raw)
