---
title: "Regenerate an API key"
method: POST
path: "/v1/orgs/{orgId}/projects/{projectId}/api-keys"
tags: ["API Keys"]
---

# Regenerate an API key

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

## Request

- Base URL: `https://api.spice.ai`
- URL: `https://api.spice.ai/v1/orgs/{orgId}/projects/{projectId}/api-keys`
- Auth: HTTP bearer

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
- `projectId` integer, required

## Headers

- `X-Org-Name` string

## Request body

- object
  - `key_number` 0 | 1 | 2: Which API key to regenerate (0 = both, 1 = primary, 2 = secondary)

## Response `200`

API key regenerated successfully

- ApiKeysRegenerated
  - `api_key` string, nullable: Primary API key
  - `api_key_2` string, nullable: Secondary API key
  - `regenerated_key` 0 | 1 | 2: Which key was regenerated (0 = both, 1 = primary, 2 = secondary)

## Other responses

- `400`: 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
- `403`: 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`: Project not found
- `500`: Internal server error

---

[API](https://skmtc.dev/spice/apis/spice-cloud-control-plane-api.md) - [All operations](https://skmtc.dev/spice/apis/spice-cloud-control-plane-api/llms.txt) - [OpenAPI document](https://skmtc.dev/spice/apis/spice-cloud-control-plane-api/revisions/5f3b75dd847d?raw)
