# Regenerate an API key

## `POST /v1/projects/{projectId}/api-keys`

Regenerates an API key for the specified project. This invalidates the previous key. Use key\_number to specify which key to regenerate (0 for both, 1 for primary, 2 for secondary).

### Path parameters

- `projectId` (integer, required): The ID of the project

### Header parameters

- `Authorization` (string, required): `Bearer <token>`. [Authentication](https://spice.ai/docs/cloud/api/management#authentication) lists the tokens it accepts.
- `X-Org-Name` (string, optional): The organization to act on, by handle. Omit it to act on the organization the credential is bound to; sending it blank is a 400, not the same as omitting it. A user credential may name any organization its owner belongs to; a machine credential is pinned to its own. A portal session token is bound to none, so it must send this header on every route but `GET /v1/orgs` (400 `org_assertion_required` otherwise). Pattern: `^[A-Za-z0-9._-]{1,255}$`.

### Request body

Optional.

Content type: `application/json`

- `key_number` (integer): Which API key to regenerate (0 = both, 1 = primary, 2 = secondary). Allowed values: `0`, `1`, `2`. Default: `1`.

### Example request

```bash
curl -X POST "https://api.spice.ai/v1/projects/<projectId>/api-keys" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "key_number": 1
  }'
```

```http
POST /v1/projects/<projectId>/api-keys HTTP/1.1
Host: api.spice.ai
Authorization: Bearer <token>
Content-Type: application/json
Content-Length: 21

{
  "key_number": 1
}
```

### Responses

**200 OK**

API key regenerated successfully

Content type: `application/json`

- `api_key` (string | null): Primary API key
- `api_key_2` (string | null): Secondary API key
- `regenerated_key` (integer): Which key was regenerated (0 = both, 1 = primary, 2 = secondary). Allowed values: `0`, `1`, `2`.

**400 Bad Request**

Invalid request body or project ID

**401 Unauthorized**

Unauthorized

**403 Forbidden**

Insufficient scope

**404 Not Found**

Project not found

**500 Internal Server Error**

Internal server error

## `POST /v1/orgs/{orgId}/projects/{projectId}/api-keys`

The org is `orgId` in the path. Regenerates an API key for the specified project. This invalidates the previous key. Use key\_number to specify which key to regenerate (0 for both, 1 for primary, 2 for secondary).

### Path parameters

- `orgId` (integer, required): The org id from GET /v1/orgs. Minimum: `1`.
- `projectId` (integer, required): The ID of the project

### Header parameters

- `Authorization` (string, required): `Bearer <token>`. [Authentication](https://spice.ai/docs/cloud/api/management#authentication) lists the tokens it accepts.
- `X-Org-Name` (string, optional): When present, X-Org-Name must name the same org as orgId. Otherwise the request returns org\_path\_mismatch (400). Pattern: `^[A-Za-z0-9._-]{1,255}$`.

### Request body

Optional.

Content type: `application/json`

- `key_number` (integer): Which API key to regenerate (0 = both, 1 = primary, 2 = secondary). Allowed values: `0`, `1`, `2`. Default: `1`.

### Example request

```bash
curl -X POST "https://api.spice.ai/v1/orgs/<orgId>/projects/<projectId>/api-keys" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "key_number": 1
  }'
```

```http
POST /v1/orgs/<orgId>/projects/<projectId>/api-keys HTTP/1.1
Host: api.spice.ai
Authorization: Bearer <token>
Content-Type: application/json
Content-Length: 21

{
  "key_number": 1
}
```

### Responses

**200 OK**

API key regenerated successfully

Content type: `application/json`

- `api_key` (string | null): Primary API key
- `api_key_2` (string | null): Secondary API key
- `regenerated_key` (integer): Which key was regenerated (0 = both, 1 = primary, 2 = secondary). Allowed values: `0`, `1`, `2`.

**400 Bad Request**

Invalid request body or project ID. orgId is not a valid org id (`invalid_org_id`), or X-Org-Name does not name that org (`org_path_mismatch`).

**401 Unauthorized**

Unauthorized

**403 Forbidden**

Insufficient scope. The caller is not a member of the org (`org_forbidden`). A machine credential named a different org (`org_assertion_mismatch`). The org is deleted (`org_deleted`).

**404 Not Found**

Project not found

**500 Internal Server Error**

Internal server error

## `POST /v1/apps/{appId}/api-keys` (deprecated)

Legacy alias of `/v1/projects/{projectId}/api-keys` — projects were previously called apps. Regenerates an API key for the specified project. This invalidates the previous key. Use key\_number to specify which key to regenerate (0 for both, 1 for primary, 2 for secondary).

### Path parameters

- `appId` (integer, required): The ID of the project

### Header parameters

- `Authorization` (string, required): `Bearer <token>`. [Authentication](https://spice.ai/docs/cloud/api/management#authentication) lists the tokens it accepts.
- `X-Org-Name` (string, optional): The organization to act on, by handle. Omit it to act on the organization the credential is bound to; sending it blank is a 400, not the same as omitting it. A user credential may name any organization its owner belongs to; a machine credential is pinned to its own. A portal session token is bound to none, so it must send this header on every route but `GET /v1/orgs` (400 `org_assertion_required` otherwise). Pattern: `^[A-Za-z0-9._-]{1,255}$`.

### Request body

Optional.

Content type: `application/json`

- `key_number` (integer): Which API key to regenerate (0 = both, 1 = primary, 2 = secondary). Allowed values: `0`, `1`, `2`. Default: `1`.

### Example request

```bash
curl -X POST "https://api.spice.ai/v1/apps/<appId>/api-keys" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "key_number": 1
  }'
```

```http
POST /v1/apps/<appId>/api-keys HTTP/1.1
Host: api.spice.ai
Authorization: Bearer <token>
Content-Type: application/json
Content-Length: 21

{
  "key_number": 1
}
```

### Responses

**200 OK**

API key regenerated successfully

Content type: `application/json`

- `api_key` (string | null): Primary API key
- `api_key_2` (string | null): Secondary API key
- `regenerated_key` (integer): Which key was regenerated (0 = both, 1 = primary, 2 = secondary). Allowed values: `0`, `1`, `2`.

**400 Bad Request**

Invalid request body or project ID

**401 Unauthorized**

Unauthorized

**403 Forbidden**

Insufficient scope

**404 Not Found**

Project not found

**500 Internal Server Error**

Internal server error

OpenAPI: [api.spice.ai/openapi.json](https://api.spice.ai/openapi.json)
