# Change an API key

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

API reference › API keys

Changes an API key. Send only the fields to change; `null` clears `expires_at`, `allowed_ips` or `monthly_spend_limit`.

A change that gives the key more power, such as a higher permission or a later expiry, must stay within the calling key's own limits. A revoked key cannot be changed, and the key of an app connected through MCP keeps its name, access and permissions.

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

## Path parameters

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

## Request body (`application/json`)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | No | At least 1 character. At most 80 characters. |
| `description` | string \| null | No | At most 500 characters. |
| `access` | string | No | How much a key may do. A `full` key holds every product at its highest level, products added later included, but never `api_keys`, which is only ever granted explicitly. A `restricted` key holds exactly the levels in its `permissions` map. One of `full`, `restricted`. |
| `permissions` | object | No | Replaces the whole map. Levels by product, such as `{"tts": "write"}`. On a `restricted` key a product left out is `none`. A `full` key already holds every other product at its highest level, so its map may name only `api_keys`. |
| `permissions.tts` | string | No | One of `none`, `read`, `write`. |
| `permissions.voices` | string | No | One of `none`, `read`, `write`. |
| `permissions.stt` | string | No | One of `none`, `write`. |
| `permissions.llm` | string | No | One of `none`, `read`, `write`. |
| `permissions.embeddings` | string | No | One of `none`, `write`. |
| `permissions.rerank` | string | No | One of `none`, `write`. |
| `permissions.account` | string | No | One of `none`, `read`. |
| `permissions.api_keys` | string | No | One of `none`, `read`, `write`. |
| `expires_at` | string \| null | No |  |
| `monthly_spend_limit` | number \| null | No | In credits per calendar month (UTC), from 0 to 999999999999.99 with at most two decimals. `null` removes the limit. |
| `enabled` | boolean | No |  |
| `allowed_ips` | string[] | No |  |

## Response (200, `application/json`)

Success.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | object | Yes |  |
| `data.id` | string | Yes | A lowercase ULID. |
| `data.name` | string | Yes |  |
| `data.description` | string \| null | Yes |  |
| `data.masked_key` | string | Yes | `nai_...` and the last four characters of the secret. |
| `data.access` | string | Yes | How much a key may do. A `full` key holds every product at its highest level, products added later included, but never `api_keys`, which is only ever granted explicitly. A `restricted` key holds exactly the levels in its `permissions` map. One of `full`, `restricted`. |
| `data.permissions` | object | Yes | The effective level for every product. A full key reads as what it can do; `api_keys` is only ever granted explicitly. |
| `data.permissions.tts` | string | Yes | One of `none`, `read`, `write`. |
| `data.permissions.voices` | string | Yes | One of `none`, `read`, `write`. |
| `data.permissions.stt` | string | Yes | One of `none`, `write`. |
| `data.permissions.llm` | string | Yes | One of `none`, `read`, `write`. |
| `data.permissions.embeddings` | string | Yes | One of `none`, `write`. |
| `data.permissions.rerank` | string | Yes | One of `none`, `write`. |
| `data.permissions.account` | string | Yes | One of `none`, `read`. |
| `data.permissions.api_keys` | string | Yes | One of `none`, `read`, `write`. |
| `data.expires_at` | string \| null | Yes | When the key stops working, or `null` for never. |
| `data.allowed_ips` | string[] | Yes | Addresses or CIDR ranges the key may be used from. Empty allows any address. |
| `data.monthly_spend_limit` | number \| null | Yes | Credits per calendar month (UTC), or `null` for no limit. |
| `data.spent_this_month` | number | Yes | Credits spent this calendar month (UTC). |
| `data.enabled` | boolean | Yes |  |
| `data.revoked_at` | string \| null | Yes |  |
| `data.last_used_at` | string \| null | Yes |  |
| `data.created_at` | string | Yes |  |
| `data.secret` | string | No | The whole key. Only in the answer to a create, and never again. |
| `request_id` | string | Yes |  |

```json
{
  "data": {
    "id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41",
    "name": "Aziza",
    "description": "string",
    "masked_key": "nai_••••••••3f9a",
    "access": "full",
    "permissions": {
      "tts": "none",
      "voices": "none",
      "stt": "none",
      "llm": "none",
      "embeddings": "none",
      "rerank": "none",
      "account": "none",
      "api_keys": "none"
    },
    "expires_at": "2026-11-17T09:30:00Z",
    "allowed_ips": [
      "203.0.113.10"
    ],
    "monthly_spend_limit": 500,
    "spent_this_month": 42.5,
    "enabled": true,
    "revoked_at": "2026-11-17T09:30:00Z",
    "last_used_at": "2026-11-17T09:30:00Z",
    "created_at": "2026-11-17T09:30:00Z",
    "secret": "nai_8xK2pQ7vR4tY9mW3nZ5b3f9a"
  },
  "request_id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41"
}
```

### Headers

| 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. |

## Errors

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 (`insufficient_permissions`), the IP is not allowed (`ip_not_allowed`), or the change would exceed the calling key's own access or limits (`insufficient_permissions`). |
| 404 | No such key in your organization: `not_found`. |
| 409 | The key is revoked and cannot be changed: `conflict`. |
| 422 | The request failed validation (`invalid_request`). `error.fields` names each invalid field. |
| 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

### TypeScript SDK

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

const client = new NeuronAI();

const key = await client.apiKeys.update("<key-id>", {enabled: false});

console.log(key.enabled);
```

### Python SDK

```python
from naiuz import NeuronAI

client = NeuronAI()

key = client.api_keys.update("<key-id>", enabled=False)

print(key.enabled)
```

### PHP SDK

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

$key = $client->apiKeys->update('<key-id>', ['enabled' => false]);

var_dump($key->enabled);
```

---

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