> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a new API key

> API key created. key is the full plaintext key, returned only once.

### Request body

`CreateApiKeyRequest`

<ParamField body="name" type="string" required />

<ParamField body="scopes" type="string[]" />

<ParamField body="expires_in_days" type="integer" />

### Response

`object`

<ResponseField name="api_key" type="object" required>
  <Expandable title="api_key">
    <ResponseField name="id" type="string (uuid)" required />

    <ResponseField name="name" type="string" required />

    <ResponseField name="key_prefix" type="string" required />

    <ResponseField name="scopes" type="string[]" required />

    <ResponseField name="last_used_at" type="string (date-time)" required />

    <ResponseField name="expires_at" type="string (date-time)" required />

    <ResponseField name="created_at" type="string (date-time)" required />
  </Expandable>
</ResponseField>

<ResponseField name="key" type="string" required>
  Full plaintext API key; shown only in this response
</ResponseField>

### Status codes

| Code  | Meaning                                                               |
| ----- | --------------------------------------------------------------------- |
| `201` | API key created. `key` is the full plaintext key, returned only once. |
| `400` | Invalid request                                                       |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://api.sandbox.stateset.app/api/v1/api-keys' \
    --header "Authorization: Bearer $STATESET_SANDBOX_API_KEY" \
    --header 'Content-Type: application/json' \
    --data '{
    "name": "Two-Person Tent",
    "scopes": [
      "sandbox:create"
    ],
    "expires_in_days": 1
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "api_key": {
      "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "name": "Two-Person Tent",
      "key_prefix": "string",
      "scopes": [
        "string"
      ],
      "last_used_at": "2026-08-31T14:22:05Z",
      "expires_at": "2026-08-31T14:22:05Z",
      "created_at": "2026-08-31T14:22:05Z"
    },
    "key": "string"
  }
  ```
</ResponseExample>
