공개·비공개 라우트 제어
공개·비공개 라우트 제어 (Control Public & Private Routes)
Enterprise 기능이에요. 이 기능은 LiteLLM Enterprise 라이선스가 필요해요. 무료 30일 체험판 시작 또는 데모 예약을 해보세요. Enterprise에 포함된 것 보기.
어떤 라우트가 인증을 요구하고 어떤 라우트가 공개적으로 접근 가능한지 제어할 수 있어요.
라우트 유형
| 라우트 유형 | 인증 요구 | 설명 |
|---|---|---|
public_routes |
아니요 | 인증 없이 접근 가능한 라우트 |
admin_only_routes |
예 (Admin만) | Proxy Admin만 접근 가능한 라우트 |
allowed_routes |
예 | 프록시에 노출되는 라우트. 설정하지 않으면 모든 라우트가 노출됨 |
빠른 시작
라우트 공개하기
인증 없이 접근할 수 있게 특정 라우트를 허용해요:
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
public_routes: ["LiteLLMRoutes.public_routes", "/spend/calculate"]
Admin 전용으로 제한하기
특정 라우트를 Proxy Admin만 접근할 수 있게 제한해요:
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
admin_only_routes: ["/key/generate", "/key/delete"]
사용 가능한 라우트 제한하기
프록시에 특정 라우트만 노출해요:
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
allowed_routes: ["/chat/completions", "/embeddings", "LiteLLMRoutes.public_routes"]
사용 예시
공개, Admin 전용, 허용 라우트 정의하기
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
public_routes: ["LiteLLMRoutes.public_routes", "/spend/calculate"]
admin_only_routes: ["/key/generate"]
allowed_routes: ["/chat/completions", "/spend/calculate", "LiteLLMRoutes.public_routes"]
LiteLLMRoutes.public_routes는 LiteLLM의 기본 공개 라우트에 대응하는 ENUM이에요. 소스 보기.
테스트
- public_routes 테스트
- admin_only_routes 테스트
- allowed_routes 테스트
curl --request POST \
--url 'http://localhost:4000/spend/calculate' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-5.6-terra",
"messages": [{"role": "user", "content": "Hey, how's it going?"}]
}'
이 엔드포인트는 Authorization 헤더 없이도 동작해요.
성공적인 요청 (Admin)
curl --location 'http://0.0.0.0:4000/key/generate' \
--header 'Authorization: Bearer ***' \
--header 'Content-Type: application/json' \
--data '{}'
실패하는 요청 (비 Admin)
curl --location 'http://0.0.0.0:4000/key/generate' \
--header 'Authorization: Bearer <virtu...min>' \
--header 'Content-Type: application/json' \
--data '{"user_role": "internal_user"}'
예상 응답
{
"error": {
"message": "user not allowed to access this route. Route=/key/generate is an admin only route",
"type": "auth_error",
"param": "None",
"code": "403"
}
}
성공적인 요청
curl http://localhost:4000/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ***" \
-d '{
"model": "fake-openai-endpoint",
"messages": [
{"role": "user", "content": "Hello, Claude"}
]
}'
실패하는 요청 (라우트 미허용)
curl --location 'http://0.0.0.0:4000/embeddings' \
--header 'Content-Type: application/json' \
-H "Authorization: Bearer ***" \
--data '{
"model": "text-embedding-ada-002",
"input": ["write a litellm poem"]
}'
예상 응답
{
"error": {
"message": "Route /embeddings not allowed",
"type": "auth_error",
"param": "None",
"code": "403"
}
}
고급: 와일드카드 패턴
와일드카드 패턴을 사용해 여러 라우트를 한 번에 매칭할 수 있어요.
문법
| 패턴 | 설명 | 예시 |
|---|---|---|
/path/* |
/path/로 시작하는 모든 라우트와 매칭 |
/api/*는 /api/users, /api/users/123과 매칭 |
예시
경로 아래 모든 라우트 공개하기
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
public_routes:
- "LiteLLMRoutes.public_routes"
- "/api/v1/*" # All routes under /api/v1/
- "/health/*" # All health check routes
Admin 전용 라우트는 와일드카드를 지원하지 않아요
admin_only_routes는 정확히 일치하는 리스트예요. /key/* 같은 패턴은 아무것도 매칭하지 않으므로, 각 라우트를 명시적으로 나열하세요:
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
admin_only_routes:
- "/key/generate"
- "/key/delete"
와일드카드 라우트 테스트
Config:
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY
public_routes:
- "/public/*"
Test:
# This works without auth (matches /public/*)
curl http://localhost:4000/public/status
# This also works without auth (matches /public/*)
curl http://localhost:4000/public/health/detailed
# This requires auth (doesn't match /public/*)
curl http://localhost:4000/private/data
출처: 문서
더 알아보기 (Learn more)
- 라우트 단위 인증 제어를 위한
general_settings구성 이해하기 - Admin 역할과 자체 서비스(Self-serve) 인증 흐름 살펴보기