Azure Model Router
Azure Model Router
Azure Model Router는 Azure AI Foundry의 기능으로, 사용자의 요구사항에 따라 요청을 가장 적합한 사용 가능한 모델로 자동 라우팅해요. 단일 엔드포인트로 각 요청에 최적의 모델을 지능적으로 선택할 수 있어요.
출처: 문서
본문
빠른 시작 (Quick Start)
모델 패턴: azure_ai/model_router/<deployment-name>
LiteLLM Python SDK:
import litellm
response = litellm.completion(
model="azure_ai/model_router/model-router", # Replace with your deployment name
messages=[{"role": "user", "content": "Hello!"}],
api_base="https://your-endpoint.cognitiveservices.azure.com/openai/v1/",
api_key="your-api-key",
)
Proxy config (config.yaml):
model_list:
- model_name: model-router
litellm_params:
model: azure_ai/model_router/model-router
api_base: https://your-endpoint.cognitiveservices.azure.com/openai/deployments/model-router/chat/completions?api-version=2025-01-01-preview
api_key: your-api-key
주요 기능 (Key Features)
- 자동 모델 선택: Azure Model Router가 요청에 가장 적합한 모델을 동적으로 선택해요
- 비용 추적: LiteLLM이 실제 사용된 모델(예: gpt-5.6-luna) 기준으로 + Model Router 인프라 수수료를 자동 추적해요
- 스트리밍 지원: 정확한 비용 계산과 함께 스트리밍 응답을 완전 지원해요
- 간단한 설정: UI 또는 설정 파일로 쉽게 구성할 수 있어요
모델 명명 패턴 (Model Naming Pattern)
패턴: azure_ai/model_router/<deployment-name>
구성 요소:
azure_ai- 공급자 식별자model_router- Model Router 배포임을 나타냄<deployment-name>- Azure AI Foundry의 실제 배포 이름 (예: azure-model-router)
예시: azure_ai/model_router/azure-model-router
동작 방식:
- LiteLLM은 요청을 Azure로 보낼 때
model_router/접두사를 자동으로 제거해요 - Azure API에는 배포 이름(예: azure-model-router)만 전송돼요
- 정확한 비용 추적을 위해 전체 경로는 응답과 로그에 보존돼요
LiteLLM Python SDK
기본 사용법 (Basic Usage)
import litellm
import os
response = litellm.completion(
model="azure_ai/model_router/azure-model-router", # Use your deployment name
messages=[{"role": "user", "content": "Hello!"}],
api_base="https://your-endpoint.cognitiveservices.azure.com/openai/v1/",
api_key=os.getenv("AZURE_MODEL_ROUTER_API_KEY"),
)
print(response)
사용량 추적과 함께 스트리밍
import litellm
import os
response = await litellm.acompletion(
model="azure_ai/model_router/azure-model-router", # Use your deployment name
messages=[{"role": "user", "content": "hi"}],
api_base="https://your-endpoint.cognitiveservices.azure.com/openai/v1/",
api_key=os.getenv("AZURE_MODEL_ROUTER_API_KEY"),
stream=True,
stream_options={"include_usage": True},
)
async for chunk in response:
print(chunk)
LiteLLM Proxy (AI Gateway)
config.yaml
참고: 모델 경로의
azure-model-router를 Azure AI Foundry의 실제 배포 이름으로 바꾸세요.
model_list:
- model_name: azure-model-router # Public name for your users
litellm_params:
model: azure_ai/model_router/azure-model-router # Use your deployment name
api_base: https://your-endpoint.cognitiveservices.azure.com/openai/v1/
api_key: os.environ/AZURE_MODEL_ROUTER_API_KEY
Proxy 시작:
litellm --config config.yaml
테스트 요청:
curl -X POST http://localhost:4000/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ***" \
-d '{
"model": "azure-model-router",
"messages": [{"role": "user", "content": "Hello!"}]
}'
LiteLLM UI로 Azure Model Router 추가하기
이 안내는 Admin Dashboard를 사용해 Azure Model Router 엔드포인트를 LiteLLM에 추가하는 방법을 보여줘요.
빠른 시작 (Quick Start)
- LiteLLM UI의 Models 페이지로 이동하기
- 공급자로 "Azure AI Foundry (Studio)" 선택하기
- 배포 이름 입력하기 (예: azure-model-router)
- LiteLLM이 자동으로
azure_ai/model_router/azure-model-router로 포맷해요 - API base URL과 API 키 추가하기
- 테스트 후 저장하기
상세 안내 (Detailed Walkthrough)
Step 1: 공급자 선택 — Models 페이지에서 "Azure AI Foundry (Studio)"를 공급자로 선택해요.
Step 2: 배포 이름 입력 — 간단한 새 방법: 텍스트 필드에 배포 이름을 직접 입력하세요. 배포 이름에 "model-router"나 "model_router"가 포함되면 LiteLLM이 자동으로 azure_ai/model_router/<deployment-name> 형식으로 만들어요.
예시:
- 입력:
azure-model-router - LiteLLM 생성:
azure_ai/model_router/azure-model-router
Azure AI Foundry에서 모델 라우터 배포 이름을 복사해 텍스트 필드에 붙여넣으세요. 내부적으로: azure-model-router를 입력하면 LiteLLM이 자동으로 model router 배포임을 감지하고 전체 모델 경로가 azure_ai/model_router/azure-model-router가 되며, API 호출 시 Azure에는 azure-model-router만 전송돼요.
Step 3: API Base와 Key 설정 — Azure Portal에서 엔드포인트 URL과 API 키를 복사해 입력해요.
Step 4: 테스트 및 모델 추가 — 설정이 동작하는지 확인하고 모델을 저장해요.
Step 5: Playground에서 확인 — 테스트하고 비용 추적이 동작하는지 확인해요. 비용은 실제 사용된 모델(예: gpt-5.6-luna) 기준 + Model Router 사용에 대한 백만 입력 토큰당 $0.14의 고정 인프라 비용으로 추적돼요.
비용 추적 (Cost Tracking)
LiteLLM이 Azure Model Router의 비용 추적을 자동으로 처리해요. 작동 방식을 이해하면 지출 해석과 결제 디버깅에 도움이 돼요.
비용 계산 방식 (How LiteLLM Calculates Cost)
Azure Model Router를 사용하면 LiteLLM이 두 가지 비용 구성 요소를 계산해요:
| 구성 요소 | 설명 | 적용 시점 |
|---|---|---|
| 모델 비용 | 요청을 처리한 실제 모델의 토큰 기반 비용 (예: gpt-5-nano, gpt-4.1-nano) | Azure가 응답에서 모델을 반환할 때 항상 |
| 라우터 고정 비용 | 백만 입력 토큰당 $0.14 (Azure AI Foundry 인프라 수수료) | 모델 라우터 엔드포인트로 요청한 경우 |
비용 계산 흐름 (Cost Calculation Flow)
- 요청 모델 감지: LiteLLM이 요청한 모델(예:
azure_ai/model_router/model-router)을 기록해요.model_router나model-router를 포함하면 라우터 요청으로 처리해요. - 응답 모델 추출: Azure가 응답에서 실제 사용된 모델(예: gpt-5.6-luna)을 반환해요. LiteLLM이 이를 모델 비용 조회에 사용해요.
- 모델 비용: LiteLLM이 응답 모델을 가격표에서 조회해 프롬프트 토큰과 완성 토큰으로 비용을 계산해요.
- 라우터 고정 비용: 원래 요청이 모델 라우터였으므로 모델 비용 위에 고정 비용(백만 입력 토큰당 $0.14)을 더해요.
- 총 비용: Total = Model Cost + Router Flat Cost
비용 추적 설정 요건
비용 추적이 제대로 동작하려면:
- 전체 패턴
azure_ai/model_router/<deployment-name>사용 (예:azure_ai/model_router/model-router) - Proxy config: LiteLLM proxy를 쓸 때
litellm_params의model을 전체 패턴으로 설정해 요청 모델이 라우터로 올바르게 식별되게 해요
# proxy_server_config.yaml
model_list:
- model_name: model-router
litellm_params:
model: azure_ai/model_router/model-router # Required for router cost detection
api_base: https://your-endpoint.cognitiveservices.azure.com/openai/deployments/model-router/chat/completions?api-version=2025-01-01-preview
api_key: your-api-key
비용 구성 (Cost Breakdown)
Azure Model Router를 사용할 때 총 비용에는 다음이 포함돼요:
- 모델 비용: 요청을 처리한 실제 모델 기준 (예: gpt-5.6-luna, gpt-5.6-terra)
- 라우터 고정 비용: 백만 입력 토큰당 $0.14 (Azure AI Foundry 인프라 수수료)
비용 포함 예시 응답
import litellm
response = litellm.completion(
model="azure_ai/model_router/azure-model-router",
messages=[{"role": "user", "content": "Hello!"}],
api_base="https://your-endpoint.cognitiveservices.azure.com/openai/v1/",
api_key="your-api-key",
)
# The response will show the actual model used
print(f"Model used: {response.model}") # e.g., "azure_ai/gpt-5.6-luna"
# Get cost (includes both model cost and router flat cost)
from litellm import completion_cost
cost = completion_cost(completion_response=response)
print(f"Total cost: ${cost}")
# Access detailed cost breakdown
if hasattr(response, '_hidden_params') and 'response_cost' in response._hidden_params:
print(f"Response cost: ${response._hidden_params['response_cost']}")