> ## 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를 생성하고 관리합니다.

## 개요

ARouter는 두 가지 유형의 키를 사용합니다:

| 키 유형        | 접두사            | 목적                                      |
| ----------- | -------------- | --------------------------------------- |
| **관리 키**    | `lr_mgmt_xxxx` | 관리 API를 통해 API Key 생성, 목록 조회, 업데이트, 삭제. |
| **API Key** | `lr_live_xxxx` | LLM 요청 수행 (채팅 완성, 임베딩 등).               |

관리 키는 범위가 지정된 접근 권한을 가진 API Key를 만들 수 있습니다:

* **허용된 제공업체** — 예: OpenAI와 Anthropic만
* **허용된 모델** — 예: `gpt-5.4`와 `claude-sonnet-4.6`만
* **소비 한도** — 일별/주별/월별 최대 예산
* **만료** — 날짜 이후 자동 만료

```
관리 키: lr_mgmt_abc123
  ├── API Key 1: lr_live_def456  (OpenAI+Anthropic, $150/월, 2025년 12월 만료)
  ├── API Key 2: lr_live_ghi789  (DeepSeek만, $50/일)
  └── API Key 3: lr_live_jkl012  (모든 제공업체, 무제한)
```

## API Key 생성

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST https://api.arouter.ai/api/v1/keys \
      -H "Authorization: Bearer lr_mgmt_xxxx" \
      -H "Content-Type: application/json" \
      -d '{
        "name": "production-backend",
        "allowed_providers": ["openai", "anthropic"],
        "allowed_models": ["gpt-5.4", "claude-sonnet-4.6"],
        "limit": 150,
        "limit_reset": "monthly",
        "expires_at": "2025-12-31T23:59:59Z"
      }'
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests

    resp = requests.post(
        "https://api.arouter.ai/api/v1/keys",
        headers={"Authorization": "Bearer lr_mgmt_xxxx"},
        json={
            "name": "production-backend",
            "allowed_providers": ["openai", "anthropic"],
            "limit": 150,
            "limit_reset": "monthly",
            "expires_at": "2025-12-31T23:59:59Z",
        },
    )
    data = resp.json()
    print("API Key:", data["key"])
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    key, err := client.CreateKey(ctx, &arouter.CreateKeyRequest{
        Name:             "production-backend",
        AllowedProviders: []string{"openai", "anthropic"},
        Limit:            float64Ptr(150),
        LimitReset:       "monthly",
    })
    fmt.Println("API Key:", key.Key)
    ```
  </Tab>

  <Tab title="Node.js">
    ```typescript theme={null}
    const key = await router.createKey({
      name: "production-backend",
      allowed_providers: ["openai", "anthropic"],
      limit: 150,
      limit_reset: "monthly",
    });
    console.log("API Key:", key.key);
    ```
  </Tab>
</Tabs>

<Info>
  `key` 필드는 생성 시 **한 번만** 반환됩니다. 안전하게 저장하세요 — 나중에 다시 가져올 수 없습니다.
</Info>

## 응답

```json theme={null}
{
  "data": {
    "hash": "abc123...",
    "name": "production-backend",
    "key_type": "regular",
    "disabled": false,
    "limit": 150,
    "limit_remaining": 150,
    "limit_reset": "monthly",
    "allowed_providers": ["openai", "anthropic"],
    "allowed_models": ["gpt-5.4", "claude-sonnet-4.6"],
    "usage": 0,
    "created_at": "2025-01-15T10:30:00Z",
    "expires_at": "2025-12-31T23:59:59Z"
  },
  "key": "lr_live_xxxxxxxxxxxxxxxx"
}
```

## API Key 목록 조회

```bash theme={null}
curl "https://api.arouter.ai/api/v1/keys?page_size=20" \
  -H "Authorization: Bearer lr_mgmt_xxxx"
```

`page_size`, `page_token`, `offset` 쿼리 매개변수로 페이지네이션을 지원합니다.

## API 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}'
```

`name`, `disabled`, `limit`, `limit_reset`, `allowed_providers`, `allowed_models`를 업데이트할 수 있습니다.

## API Key 삭제

```bash theme={null}
curl -X DELETE https://api.arouter.ai/api/v1/keys/KEY_HASH \
  -H "Authorization: Bearer lr_mgmt_xxxx"
```

삭제된 키는 즉시 무효화되며 복원할 수 없습니다.

## 사용 사례

| 시나리오        | 구성                              |
| ----------- | ------------------------------- |
| **서비스별 격리** | 특정 모델 접근으로 마이크로서비스당 하나의 API Key |
| **비용 관리**   | 팀 또는 환경별 소비 한도                  |
| **임시 접근**   | `expires_at`이 있는 계약자용 단기 키      |
| **제공업체 잠금** | 스테이징을 저렴한 모델로만 제한               |
| **속도 보호**   | 대시보드를 통해 키별 한도 조정               |
