# Create a service account

Requires a current owner/admin browser session. The credential is returned only once. Retrying returns its identity; rotate if the secret was lost.

`POST /api/service-accounts`

## Parameters

| Name | In | Type | Required | Description |

| --- | --- | --- | --- | --- |

| `Idempotency-Key` | header | `string` | No | Required for writes authenticated by a service credential and for service-account lifecycle writes. Other session writes may opt in. Reuse the key and payload for retries. Settled keys remain reserved for at least seven days; a transient 4xx releases its key. Changed payloads return 409. Match any legacy clientOperationId/clientMessageId in the body. |

## Request body

| Field | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| `name` | `string` | Yes | min length 1, max length 100 | — |
| `permissions` | `object` | Yes | — | — |
| `permissions.project` | `string[]` | No | max 4 items | — |
| `permissions.project.[item]` | `string` | No | create · read · update · delete | — |
| `permissions.thread` | `string[]` | No | max 6 items | — |
| `permissions.thread.[item]` | `string` | No | create · read · update · delete · stop · retry | — |
| `permissions.repo` | `string[]` | No | max 2 items | — |
| `permissions.repo.[item]` | `string` | No | read · update | — |
| `permissions.mcpServer` | `string[]` | No | max 4 items | — |
| `permissions.mcpServer.[item]` | `string` | No | create · read · update · delete | — |
| `permissions.modelKey` | `string[]` | No | max 1 items | — |
| `permissions.modelKey.[item]` | `string` | No | read | — |
| `permissions.usage` | `string[]` | No | max 1 items | — |
| `permissions.usage.[item]` | `string` | No | read | — |
| `permissions.webhook` | `string[]` | No | max 4 items | — |
| `permissions.webhook.[item]` | `string` | No | create · read · update · delete | — |
| `permissions.automation` | `string[]` | No | max 5 items | — |
| `permissions.automation.[item]` | `string` | No | create · read · update · delete · run | — |
| `projectIds` | `string[] \| null` | No | — | Restricts resource access to these projects. Organization-wide repository discovery and billing are unavailable with project restrictions; repo:read alone does not enable discovery. |
| `projectIds.Option 1` | `string[]` | No | max 100 items, min 1 items | — |
| `projectIds.Option 1.[item]` | `string` | No | min length 1, max length 128 | — |
| `projectIds.Option 2` | `null` | No | — | — |

```json
{
  "name": "Factory worker",
  "permissions": {
    "project": [
      "read"
    ],
    "thread": [
      "create",
      "read",
      "update"
    ]
  },
  "projectIds": [
    "project_example"
  ]
}
```

## Example request

```bash
curl --request POST \
  --url https://api.hoplite.sh/api/service-accounts \
  --header "Cookie: $HOPLITE_SESSION_COOKIE" \
  --header "Idempotency-Key: $HOPLITE_OPERATION_ID" \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "Factory worker",
  "permissions": {
    "project": [
      "read"
    ],
    "thread": [
      "create",
      "read",
      "update"
    ]
  },
  "projectIds": [
    "project_example"
  ]
}'
```

## 201 response

Successful response

Content type: `application/json`. Response type: `object`.

| Field | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| `ok` | `boolean` | Yes | constant true | — |
| `account` | `object` | Yes | — | — |
| `account.id` | `string` | Yes | — | — |
| `account.orgId` | `string` | Yes | — | — |
| `account.name` | `string` | Yes | — | — |
| `account.permissions` | `object` | Yes | — | — |
| `account.permissions.project` | `string[]` | No | max 4 items | — |
| `account.permissions.project.[item]` | `string` | No | create · read · update · delete | — |
| `account.permissions.thread` | `string[]` | No | max 6 items | — |
| `account.permissions.thread.[item]` | `string` | No | create · read · update · delete · stop · retry | — |
| `account.permissions.repo` | `string[]` | No | max 2 items | — |
| `account.permissions.repo.[item]` | `string` | No | read · update | — |
| `account.permissions.mcpServer` | `string[]` | No | max 4 items | — |
| `account.permissions.mcpServer.[item]` | `string` | No | create · read · update · delete | — |
| `account.permissions.modelKey` | `string[]` | No | max 1 items | — |
| `account.permissions.modelKey.[item]` | `string` | No | read | — |
| `account.permissions.usage` | `string[]` | No | max 1 items | — |
| `account.permissions.usage.[item]` | `string` | No | read | — |
| `account.permissions.webhook` | `string[]` | No | max 4 items | — |
| `account.permissions.webhook.[item]` | `string` | No | create · read · update · delete | — |
| `account.permissions.automation` | `string[]` | No | max 5 items | — |
| `account.permissions.automation.[item]` | `string` | No | create · read · update · delete · run | — |
| `account.projectIds` | `string[] \| null` | Yes | — | — |
| `account.projectIds.Option 1` | `string[]` | No | — | — |
| `account.projectIds.Option 1.[item]` | `string` | No | — | — |
| `account.projectIds.Option 2` | `null` | No | — | — |
| `account.disabled` | `boolean` | Yes | — | — |
| `account.createdAt` | `string<date-time>` | Yes | — | — |
| `account.updatedAt` | `string<date-time>` | Yes | — | — |
| `credential` | `object` | Yes | — | — |
| `credential.id` | `string` | Yes | — | — |
| `credential.accountId` | `string` | Yes | — | — |
| `credential.expiresAt` | `string<date-time>` | Yes | — | — |
| `credential.revoked` | `boolean` | Yes | — | — |
| `credential.createdAt` | `string<date-time>` | Yes | — | — |
| `key` | `string` | No | — | — |
| `secretUnavailable` | `boolean` | No | — | — |

```json

```

## Response headers

| Header | Type | Statuses | Description |

| --- | --- | --- | --- |

| `RateLimit` | `string` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Current ingress policy, remaining requests, and seconds until reset, for example `"ingress";r=599;t=60`. |

| `RateLimit-Policy` | `string` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Ingress quota and window, for example `"ingress";q=600;qu="requests";w=60`. |

| `X-RateLimit-Limit` | `integer` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Maximum requests allowed in the current rolling window. |

| `X-RateLimit-Remaining` | `integer` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Requests remaining in the current rolling window. |

| `X-RateLimit-Reset` | `integer` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Unix timestamp when the current rolling window resets. |

| `x-request-id` | `string` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Request correlation ID. |

| `Retry-After` | `integer` | `429`, `503` | Seconds until another request should be attempted. |

| `X-Retry-After` | `integer` | `429`, `503` | Legacy retry delay in seconds. |

## Status codes

- `201` — Successful response

- `400` — Invalid request. Validation responses include field paths.

- `401` — The API key is missing, invalid, or lacks the operation's permission.

- `402` — The organization does not have access to the requested product capability.

- `403` — The key's current user no longer has the required organization membership or role.

- `404` — The resource is not available in the authenticated scope.

- `409` — The request conflicts with a retry receipt or current resource state.

- `410` — The event cursor has expired; capture a fresh head and resource snapshot.

- `429` — The API-key rate limit has been exceeded.

- `500` — The API encountered an unexpected failure.

- `501` — The deployment has not configured the requested capability.

- `503` — A required API dependency, including the rate limiter, is unavailable.