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

# Create API key

> Create a new API key. Returns the plain text token which is only shown once.

## Request

<ParamField body="name" type="string" required>
  The API key name. Maximum 255 characters.
</ParamField>

<ParamField body="expires_at" type="string">
  Optional expiration. Any date string the server can parse (e.g. `2026-12-31`, `2026-12-31T15:00:00Z`), must be after today. Omit for a non-expiring key.
</ParamField>

## Response

Returns `201` with the new key plus the plain token. The plain token is shown only here — store it immediately.

<ResponseField name="token" type="object">
  Same shape as one entry in [`GET /api-keys`](/api-reference/endpoint/list-api-keys) — `id`, `name`, `last_used_at`, `expires_at`, `created_at` (all timestamps ISO 8601).
</ResponseField>

<ResponseField name="plain_token" type="string">
  The opaque bearer token to send in `Authorization: Bearer …`. Never returned again.
</ResponseField>

<Warning>
  Copy the `plain_token` immediately after creation. TryPost stores a hash of your API key, not the key itself. If you lose it, you'll need to create a new one.
</Warning>

<RequestExample>
  ```bash theme={null}
  curl -X POST https://app.trypost.it/api/api-keys \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "CI/CD Pipeline",
      "expires_at": "2025-12-31"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "token": {
      "id": "a7b8c9d0-e1f2-3a4b-5c6d-7e8f9a0b1c2d",
      "name": "CI/CD Pipeline",
      "last_used_at": null,
      "expires_at": "2025-12-31T00:00:00+00:00",
      "created_at": "2025-01-14T12:00:00+00:00"
    },
    "plain_token": "9f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a..."
  }
  ```
</ResponseExample>
