---
title: "Create API key for service user"
url: https://hexelstudio.com/docs/api/ciam-iam/service-users/create-api-key-for-service-user
---

# Create API key for service user

**POST** `/service-users/{service_user_id}/api-keys`

## Path parameters

- `service_user_id: string`

  Service User ID

## Headers

- `Authorization: string`

  `Bearer <token>`.

## Body parameters

- `created_at: optional string`

- `created_by_user_id: optional string`

- `description: optional string`

- `environment_id: optional string`

- `expires_at: optional string`

- `id: optional string`

- `key_prefix: optional string`

- `last_used_at: optional string`

- `name: optional string`

- `organization_id: optional string`

- `revoked_at: optional string`

- `revoked_by_user_id: optional string`

- `service_user_id: optional string`

- `workspace_id: optional string`

## Returns

`201` Created (`APIKeyCreateResponse`)

- `api_key: optional string`

- `expires_at: optional string`

  ExpiresAt is always set: the requested expiry, or the default lifetime.

- `id: optional string`

- `key_prefix: optional string`

## Errors

- `400` Bad Request

## Example

```bash
curl --request POST \
  --url 'https://api.hexelstudio.com/v1/service-users/{service_user_id}/api-keys' \
  --header "Authorization: Bearer $ACCESS_TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{
  "created_at": "2026-01-01T00:00:00Z",
  "created_by_user_id": "string",
  "description": "string",
  "environment_id": "string",
  "expires_at": "2026-01-01T00:00:00Z",
  "id": "string",
  "key_prefix": "string",
  "last_used_at": "2026-01-01T00:00:00Z",
  "name": "string",
  "organization_id": "string",
  "revoked_at": "2026-01-01T00:00:00Z",
  "revoked_by_user_id": "string",
  "service_user_id": "string",
  "workspace_id": "string"
}'
```

### Response (201)

```json
{
  "api_key": "string",
  "expires_at": "2026-01-01T00:00:00Z",
  "id": "string",
  "key_prefix": "string"
}
```

### Response (400)

```json
{
  "key": "string"
}
```
