> ## 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 요청의 user 필드를 사용하여 애플리케이션의 개별 사용자 사용량을 추적합니다. 사용자별 분석, 비용 배분, 남용 감지에 유용합니다.

ARouter는 API 요청에 `user` 필드를 전달하여 사용자별 사용량 추적을 지원합니다. 이를 통해 애플리케이션의 개별 사용자에게 API 비용을 귀속시키고 사용자 수준에서 사용 패턴을 모니터링할 수 있습니다.

## 사용자 ID 전달하기

채팅 완성 요청에 `user` 필드를 포함합니다:

```json theme={null}
{
  "model": "openai/gpt-5.4",
  "messages": [{"role": "user", "content": "Hello!"}],
  "user": "user_12345"
}
```

`user` 값은 시스템에서 최종 사용자를 식별하는 임의의 문자열이 될 수 있습니다 — 데이터베이스 ID, 해시된 이메일, 또는 세션 ID. ARouter는 이 값을 검증하거나 해석하지 않습니다.

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    import OpenAI from "openai";

    const client = new OpenAI({
      baseURL: "https://api.arouter.ai/v1",
      apiKey: "lr_live_xxxx",
    });

    async function chatWithUser(userId: string, message: string) {
      const response = await client.chat.completions.create({
        model: "openai/gpt-5.4",
        messages: [{ role: "user", content: message }],
        user: userId,
      });
      return response.choices[0].message.content;
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from openai import OpenAI

    client = OpenAI(
        base_url="https://api.arouter.ai/v1",
        api_key="lr_live_xxxx",
    )

    def chat_with_user(user_id: str, message: str) -> str:
        response = client.chat.completions.create(
            model="openai/gpt-5.4",
            messages=[{"role": "user", "content": message}],
            user=user_id,
        )
        return response.choices[0].message.content
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl https://api.arouter.ai/v1/chat/completions \
      -H "Authorization: Bearer lr_live_xxxx" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "openai/gpt-5.4",
        "messages": [{"role": "user", "content": "Hello!"}],
        "user": "user_12345"
      }'
    ```
  </Tab>
</Tabs>

***

## 개인 정보 고려사항

<Warning>
  `user` 값으로 개인 식별 정보(PII)를 전달하지 마세요. 해시된 ID나 데이터베이스 기본 키와 같은 불투명한 식별자를 사용하세요.
</Warning>

권장 방식:

```python theme={null}
import hashlib

# 전달하기 전에 사용자 이메일 해시 처리
user_id = hashlib.sha256(user_email.encode()).hexdigest()[:16]

# 또는 불투명한 데이터베이스 ID 사용
user_id = str(user.id)  # 예: "usr_abc123"
```

***

## 사용자별 사용량 보기

사용자 수준 사용량 데이터는 [활동 내보내기](/ko/guides/administration/activity-export)에서 확인할 수 있습니다. 각 레코드에는 전달한 `user` 필드가 포함되어 다음이 가능합니다:

* 사용자별 Token 소비 및 비용 계산
* 용량 계획을 위한 고사용량 사용자 파악
* 비정상적인 사용 패턴이나 남용 감지
* 최종 사용자를 위한 사용량 기반 청구 구축

### 활동 내보내기 API

사용자별로 필터링하여 사용 기록 조회:

```bash theme={null}
curl "https://api.arouter.ai/v1/activity?user=user_12345&limit=100" \
  -H "Authorization: Bearer lr_live_xxxx"
```

***

## 사용 사례

### 사용자별 비용 배분

각 고객을 서비스하는 데 드는 비용 추적:

```typescript theme={null}
// 고객 ID 전달
const response = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-4.6",
  messages: conversation,
  user: `customer_${customerId}`,
});

// 나중에: 활동 내보내기를 조회하여 고객별 총 비용 확인
```

### 남용 감지

사용자별 비정상적인 사용 패턴 모니터링:

```python theme={null}
# 각 사용자에게 고유한 식별자 부여
response = client.chat.completions.create(
    model="openai/gpt-5.4",
    messages=[{"role": "user", "content": user_message}],
    user=f"app_user_{user.id}",
)
```

### 멀티 테넌트 애플리케이션

멀티 테넌트 SaaS 애플리케이션에서 조직 또는 테넌트 ID 전달:

```typescript theme={null}
const response = await client.chat.completions.create({
  model: "google/gemini-2.5-flash",
  messages: messages,
  user: `org_${organizationId}`,
});
```

***

## 참고 사항

* `user` 필드는 선택 사항입니다. 이 필드가 없는 요청도 API 키의 집계 사용량으로 추적됩니다.
* 사용자 ID는 불투명한 문자열로 저장됩니다. ARouter는 형식을 검증, 파싱 또는 해석하지 않습니다.
* 사용자 추적 데이터는 [활동 내보내기](/ko/guides/administration/activity-export) 레코드에 포함됩니다.
* 팀 수준의 사용량 제어는 [조직 관리](/ko/guides/administration/organization-management)를 참조하세요.
