# Revoke an API key

`POST https://my.neuronai.uz/api/v1/api-keys/{id}/revoke`

Справочник API › API ключи

Revokes an API key for good. It stops working at once, and its usage history stays.

A key can revoke itself, to rotate. Revoking the key of a connected app also disconnects the app.

**Authentication:** `Authorization: Bearer <API key>`, a key with `api_keys:write`.

## Параметры пути

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | The key id: a lowercase ULID. |

## Ответ (204, no body)

No content

### Заголовки

| Header | Type | Description |
| --- | --- | --- |
| `X-Request-Id` | string | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |
| `X-RateLimit-Limit` | integer | The requests a minute the rate limit on this endpoint allows. Sent once the limit has counted the request, so not when the key itself is refused. |
| `X-RateLimit-Remaining` | integer | How many of them are left this minute. |

## Ошибки

Every error has the same JSON shape:

```json
{
  "error": {
    "type": "invalid_request_error",
    "code": "invalid_request",
    "message": "The request is malformed or failed validation.",
    "param": null
  },
  "request_id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41"
}
```

| Status | Meaning |
| --- | --- |
| 401 | The API key is missing or not recognized (`invalid_api_key`), revoked (`api_key_revoked`), disabled (`api_key_disabled`) or expired (`api_key_expired`). |
| 403 | The key lacks the permission this endpoint needs (`insufficient_permissions`), or the client IP is not in its allowlist (`ip_not_allowed`). |
| 404 | No such key in your organization: `not_found`. |
| 429 | A rate or concurrency limit was reached (`rate_limit_exceeded`, `concurrency_limit_exceeded`). Retry after `Retry-After` seconds. |
| default | Any other error, in the same shape, such as `server_error` (500) or `service_unavailable` (503). |

## Examples

### cURL

```bash
# Rotate a key safely: create the replacement first, move your apps to
# its secret, and only then revoke the old key below.
curl -X POST "https://my.neuronai.uz/api/v1/api-keys/<key-id>/revoke" \
  -H "Authorization: Bearer <your-api-key>"
# 204 No Content
```

### TypeScript SDK

```typescript
import {NeuronAI} from "@naiuz/sdk";

const client = new NeuronAI();

// Rotate a key safely: create the replacement first, move your apps to it, then revoke the old key.
await client.apiKeys.revoke("<key-id>");
```

### Python SDK

```python
from naiuz import NeuronAI

client = NeuronAI()

# Rotate a key safely: create the replacement first, move your apps to it, then revoke the old key.
client.api_keys.revoke("<key-id>")
```

### PHP SDK

```php
$client = new \Naiuz\NeuronAI();

// Rotate a key safely: create the replacement first, move your apps to it, then revoke the old key.
$client->apiKeys->revoke('<key-id>');
```

### JavaScript

```javascript
// Rotate a key safely: create the replacement first, move your apps to
// its secret, and only then revoke the old key below.
const response = await fetch('https://my.neuronai.uz/api/v1/api-keys/<key-id>/revoke', {
    method: 'POST',
    headers: { 'Authorization': 'Bearer <your-api-key>' },
});

if (response.status !== 204) {
    throw new Error(`Request failed: ${response.status}`);
}
```

### Python

```python
import requests

# Rotate a key safely: create the replacement first, move your apps to
# its secret, and only then revoke the old key below.
response = requests.post("https://my.neuronai.uz/api/v1/api-keys/<key-id>/revoke", headers={"Authorization": "Bearer <your-api-key>"})
response.raise_for_status()  # 204 No Content
```

### PHP

```php
// Rotate a key safely: create the replacement first, move your apps to
// its secret, and only then revoke the old key below.
$ch = curl_init('https://my.neuronai.uz/api/v1/api-keys/<key-id>/revoke');

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer <your-api-key>'],
]);

curl_exec($ch); // 204 No Content
curl_close($ch);
```

---

Source: https://docs.neuronai.uz/ru/api/reference/api-keys/revoke-api-key
