LiteLLM 프록시 퀵 스타트
LiteLLM 프록시 퀵 스타트 (CLI - Quick Start)
LiteLLM 프록시(LiteLLM Server, LLM 게이트웨이)를 CLI로 빠르게 띄워 보는 시간이에요. 명령어 몇 줄이면 100개가 넘는 LLM을 하나의 OpenAI 호환 인터페이스 뒤에 모아 둘 수 있어요. 프록시가 정확히 뭘 해 주는지, 어떻게 시작하는지를 함께 따라가 볼게요.
출처: 공식문서
LiteLLM 프록시가 관리해 주는 것
- 통합 인터페이스(Unified Interface) — Huggingface, Bedrock, TogetherAI 등 100개 이상의 LLM을 OpenAI의
ChatCompletions·Completions형식으로 호출하게 해 줘요. - 비용 추적(Cost Tracking) — 가상 키를 통한 인증, 지출 추적, 예산 관리.
- 로드 밸런싱(Load Balancing) — 여러 모델·같은 모델의 여러 배포 간에 부하를 분산해요. 부하 테스트에서 1.5k+ requests/second를 처리할 수 있어요.
설치
uv를 쓰면 이렇게 간단해요.
$ uv tool install 'litellm[proxy]'
Python 3.10 이상이 필요해요. LiteLLM 1.84.0부터 requires-python >=3.10이라서죠. uv tool install은 호환되는 파이썬을 알아서 준비해 주지만, 맨 pip install 'litellm[proxy]'은 그렇게 하지 않아요. Python 3.9에서 pip은 에러 없이 3.9를 허용하는 마지막 릴리스(1.83.9)로 조용히 내려가 버려요. 예상치 못하게 옛 버전이 설치됐다면 python --version을 확인하고 3.10+로 올린 뒤 재설치하세요.
첫 프록시 실행
모델을 정해 실행하면 프록시가 뜹니다.
$ litellm --model huggingface/bigcode/starcoder
# INFO: Proxy running on http://0.0.0.0:4000
상세 디버그 로그가 필요하면 --detailed_debug를 붙여 실행해요.
$ litellm --model huggingface/bigcode/starcoder --detailed_debug
새 셸에서 다음 명령을 내리면 openai.chat.completions 요청이 만들어져요. openai v1.0.0 이상을 쓰고 있는지 확인하세요.
$ litellm --test
이러면 gpt-3.5-turbo 요청이 자동으로 Huggingface inference endpoint에 호스팅된 bigcode starcoder로 라우팅돼요. LiteLLM이 지원하는 모든 LLM이 프록시 위에서 동작합니다 — AWS Bedrock, Azure OpenAI, OpenAI, Ollama, OpenAI 호환 엔드포인트, Vertex AI(Gemini), Huggingface(TGI), AWS Sagemaker, Anthropic, VLLM, TogetherAI, Replicate, Cohere 등등.
config.yaml로 모델 목록 만들기
config로 모델 리스트를 만들고 api_base, max_tokens 등(litellm의 모든 파라미터)을 지정할 수 있어요. 예시 설정을 볼게요.
model_list:
- model_name: gpt-3.5-turbo # 사용자에게 보이는 모델 별칭
litellm_params: # litellm.completion()이 받는 모든 파라미터
model: azure/<your-deployment-name>
api_base: <your-azure-api-endpoint>
api_key: <your-azure-api-key>
- model_name: gpt-3.5-turbo
litellm_params:
model: azure/gpt-turbo-small-ca
api_base: https://my-endpoint-canada-berri992.openai.azure.com/
api_key: <your-azure-api-key>
- model_name: vllm-model
litellm_params:
model: openai/<your-model-name>
api_base: <your-vllm-api-base> # e.g. http://0.0.0.0:3000/v1
api_key: <your-vllm-api-key | none>
이제 config로 프록시를 실행해요.
$ litellm --config your_config.yaml
LiteLLM은 OpenAI SDK, Anthropic SDK, Mistral SDK, LlamaIndex, Langchain(JS, Python) 등 여러 SDK와 호환돼요.
요청 보내기
가장 기본적인 curl 요청 예시입니다.
curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-3.5-turbo",
"messages": [
{ "role": "user", "content": "what llm are you" }
]
}'
프록시가 노출하는 주요 엔드포인트를 정리하면 이래요.
POST /chat/completions— 100개 이상의 LLM을 호출하는 채팅 완성 엔드포인트POST /completions— 완성(completions) 엔드포인트POST /embeddings— Azure, OpenAI, Huggingface 엔드포인트용 임베딩 엔드포인트GET /models— 서버에서 사용 가능한 모델 나열POST /key/generate— 프록시 접근용 키 생성
로그 레벨 조절
- 기본 로그:
litellm --model gpt-3.5-turbo --debug또는export LITELLM_LOG=INFO - 상세 로그:
--detailed_debug또는export LITELLM_LOG=DEBUG - 로그 끄기:
export LITELLM_LOG=None