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

# 更新 API Key

> 更新现有 API key 的名称、状态、消费限额或访问限制。需要管理 key。

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

请求体中的所有字段均为可选——仅包含您想要更改的字段。

## 禁用 / 启用 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}'
```

被禁用的 key 会立即停止接受请求。设置 `disabled: false` 可重新启用。

## 更新消费限额

```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"
  }'
```

将 `limit` 设置为 `null` 可移除消费上限。`limit_reset` 字段控制计数器何时重置：`daily`（UTC 午夜）、`weekly`（周一 UTC 午夜）或 `monthly`（每月 1 日 UTC 午夜）。设置为 `null` 表示终身上限。
