> ## Documentation Index
> Fetch the complete documentation index at: https://docs.arouter.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Update API Key

> Update an existing API key's name, status, spending limits, or access restrictions. Management key required.

<RequestExample>
  ```bash cURL theme={null}
  curl -X PATCH https://api.arouter.ai/api/v1/keys/KEY_HASH \
    -H "Authorization: Bearer lr_mgmt_xxxx" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "production-backend-v2",
      "limit": 200,
      "limit_reset": "monthly",
      "allowed_providers": ["openai", "anthropic", "google"],
      "allowed_models": ["openai/gpt-5.4", "anthropic/claude-sonnet-4.6", "google/gemini-2.5-flash"]
    }'
  ```

  ```python Python theme={null}
  import requests

  resp = requests.patch(
      "https://api.arouter.ai/api/v1/keys/KEY_HASH",
      headers={"Authorization": "Bearer lr_mgmt_xxxx"},
      json={
          "name": "production-backend-v2",
          "limit": 200,
          "limit_reset": "monthly",
          "allowed_providers": ["openai", "anthropic", "google"],
      },
  )
  print(resp.json())
  ```

  ```go Go theme={null}
  updated, err := client.UpdateKey(ctx, "KEY_HASH", &arouter.UpdateKeyRequest{
      Name:             stringPtr("production-backend-v2"),
      Limit:            float64Ptr(200),
      LimitReset:       stringPtr("monthly"),
      AllowedProviders: []string{"openai", "anthropic", "google"},
  })
  ```

  ```typescript Node.js theme={null}
  const updated = await router.updateKey("KEY_HASH", {
    name: "production-backend-v2",
    limit: 200,
    limit_reset: "monthly",
    allowed_providers: ["openai", "anthropic", "google"],
  });
  console.log(updated.data.name); // "production-backend-v2"
  ```
</RequestExample>

All fields in the request body are optional — only include the fields you want to change.

## Disable / Enable a Key

```bash theme={null}
curl -X PATCH https://api.arouter.ai/api/v1/keys/KEY_HASH \
  -H "Authorization: Bearer lr_mgmt_xxxx" \
  -H "Content-Type: application/json" \
  -d '{"disabled": true}'
```

Disabled keys immediately stop accepting requests. Set `disabled: false` to re-enable.

## Update Spending Limits

```bash theme={null}
curl -X PATCH https://api.arouter.ai/api/v1/keys/KEY_HASH \
  -H "Authorization: Bearer lr_mgmt_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "limit": 500,
    "limit_reset": "monthly"
  }'
```

Set `limit` to `null` to remove the spending cap. The `limit_reset` field controls when the counter resets: `daily` (midnight UTC), `weekly` (Monday midnight UTC), or `monthly` (1st of month midnight UTC). Set to `null` for a lifetime cap.
