> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.mitu.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.mitu.ai/_mcp/server.

# Rotate key

POST https://api.mitu.ai/v1/customers/{id}/keys/{keyId}/rotate
Content-Type: application/json

Replace a customer key with a new one, returned in full only once.

Reference: https://docs.mitu.ai/api-reference/agent-access/rotate-customer-key

## Authentication

- `x-api-key` header (required) — Your API key, using a test key for the sandbox and a live key for production.

## Servers

- `https://api.mitu.ai` (Production, default)
- `https://sandbox-api.mitu.ai` (Sandbox)

## Request

### Path parameters

- `id` (string, required) — Unique identifier of the resource.
- `keyId` (string, required) — The identifier of the customer key.

### Headers

- `Idempotency-Key` (string, optional) — Unique key used to safely retry the same state-changing request.

### Body (application/json)

This endpoint expects a RotateCustomerKey.

- `expires_at` (datetime, optional, nullable) — The expiry of the new key. Leave it out to keep the previous expiry, or send null for a key that never expires.

## Response

### 201

Key rotated successfully.

- `message` (string, required)
- `data` (IssuedCustomerKey, required)

## Errors

### 400 Bad Request Error

The request is invalid and could not be processed.

- `statusCode` (integer, required) — The HTTP status code of the response.
- `message` (ErrorResponseMessage, required) — What went wrong. For a request that fails validation, a list with one entry for each field to correct.
- `error` (string, required) — The name of the HTTP status.

### 401 Unauthorized Error

Authentication failed because the API key is missing or invalid.

- `statusCode` (integer, required) — The HTTP status code of the response.
- `message` (ErrorResponseMessage, required) — What went wrong. For a request that fails validation, a list with one entry for each field to correct.
- `error` (string, required) — The name of the HTTP status.

### 403 Forbidden Error

The authenticated account is not allowed to perform this action.

- `statusCode` (integer, required) — The HTTP status code of the response.
- `message` (ErrorResponseMessage, required) — What went wrong. For a request that fails validation, a list with one entry for each field to correct.
- `error` (string, required) — The name of the HTTP status.

### 404 Not Found Error

The requested resource could not be found.

- `statusCode` (integer, required) — The HTTP status code of the response.
- `message` (ErrorResponseMessage, required) — What went wrong. For a request that fails validation, a list with one entry for each field to correct.
- `error` (string, required) — The name of the HTTP status.

### 409 Conflict Error

The request conflicts with the current state of the resource.

- `statusCode` (integer, required) — The HTTP status code of the response.
- `message` (ErrorResponseMessage, required) — What went wrong. For a request that fails validation, a list with one entry for each field to correct.
- `error` (string, required) — The name of the HTTP status.

### 429 Too Many Requests Error

Too many requests were sent in a short period.

- `statusCode` (integer, required) — The HTTP status code of the response.
- `message` (ErrorResponseMessage, required) — What went wrong. For a request that fails validation, a list with one entry for each field to correct.
- `error` (string, required) — The name of the HTTP status.

### 500 Internal Server Error

An unexpected error occurred while processing the request.

- `statusCode` (integer, required) — The HTTP status code of the response.
- `message` (ErrorResponseMessage, required) — What went wrong. For a request that fails validation, a list with one entry for each field to correct.
- `error` (string, required) — The name of the HTTP status.

## Types

### IssuedCustomerKey

- `id` (string, optional)
- `name` (string, optional)
- `prefix` (string, optional) — The first characters of the key, so you and the customer can tell which key is which without the full key being shown.
- `status` (enum, optional)
  - Allowed values: `active`, `expired`, `revoked`
- `expires_at` (datetime, optional, nullable)
- `last_used_at` (datetime, optional, nullable)
- `rotated_at` (datetime, optional, nullable)
- `revoked_at` (datetime, optional, nullable)
- `created_at` (datetime, optional)
- `key` (string, optional) — The full customer key, returned only in this response. Mitu does not store the key in a form that can be shown again, so store it or deliver it to the customer straight away. A lost key is replaced with Rotate key.
- `mcp_url` (string, optional, nullable) — The MCP address the customer adds to their AI app.

### ErrorResponseMessage

What went wrong. For a request that fails validation, a list with one entry for each field to correct.

- string
- list of string

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "message": "Key created successfully",
  "data": {
    "id": "cwk_4m8q2v7x1c9z",
    "name": "Claude desktop",
    "prefix": "mcpk_7f3a9c2e",
    "status": "active",
    "expires_at": "2027-05-01T00:00:00.000Z",
    "last_used_at": null,
    "rotated_at": null,
    "revoked_at": null,
    "created_at": "2026-09-11T15:00:34.915Z",
    "key": "<customer_key>",
    "mcp_url": "https://mcp.mitu.ai/@yourbusiness"
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.mitu.ai/v1/customers/id/keys/keyId/rotate"

payload = {}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.mitu.ai/v1/customers/id/keys/keyId/rotate';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.mitu.ai/v1/customers/id/keys/keyId/rotate"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.mitu.ai/v1/customers/id/keys/keyId/rotate")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.mitu.ai/v1/customers/id/keys/keyId/rotate")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.mitu.ai/v1/customers/id/keys/keyId/rotate', [
  'body' => '{}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.mitu.ai/v1/customers/id/keys/keyId/rotate");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.mitu.ai/v1/customers/id/keys/keyId/rotate")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```