[BETA] 요청 우선순위화

[BETA] 요청 우선순위화 (Request Prioritization)

트래픽이 많은 환경에서 LLM API 요청에 우선순위를 매길 수 있는 베타 기능이에요. 요청을 우선순위 큐에 추가하고, 폴링하며, 건강한 배포가 있거나 요청이 큐 맨 위에 있을 때 호출을 수행해요.

출처: 문서

본문

info

베타 기능이에요. 테스트용으로만 사용하세요.

트래픽이 많은 환경에서 LLM API 요청에 우선순위를 매겨요.

  • 요청을 우선순위 큐에 추가해요.
  • 큐를 폴링해 요청을 만들 수 있는지 확인해요. 다음 경우 'True'를 반환해요:
    • 건강한 배포가 있으면
    • 또는 요청이 큐 맨 위에 있으면
  • 우선순위 - 숫자가 낮을수록 우선순위가 높아요:
    • 예: priority=0 > priority=2000

지원되는 Router 엔드포인트:

  • acompletion (프록시 /v1/chat/completions)
  • atext_completion (프록시 /v1/completions)

Quick Start

from litellm import Router

router = Router(
    model_list=[
        {
            "model_name": "gpt-5.6-luna",
            "litellm_params": {
                "model": "gpt-5.6-luna",
                "mock_response": "Hello world this is Macintosh!", # fakes the LLM API call
                "rpm": 1,
            },
        },
    ],
    timeout=2, # timeout request if takes > 2s
    routing_strategy="simple-shuffle", # recommended for best performance
    polling_interval=0.03 # poll queue every 3ms if no healthy deployments
)

try:
    _response = await router.acompletion( # 👈 ADDS TO QUEUE + POLLS + MAKES CALL
        model="gpt-5.6-luna",
        messages=[{"role": "user", "content": "Hey!"}],
        priority=0, # 👈 LOWER IS BETTER
    )
except Exception as e:
    print("didn't make request")

LiteLLM 프록시

LiteLLM 프록시에서 요청에 우선순위를 매기려면 요청에 priority를 추가하세요.

  • curl
  • OpenAI SDK
curl -X POST 'http://localhost:4000/chat/completions' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ***" \
-D '{
    "model": "gpt-3.5-turbo-fake-model",
    "messages": [
        {
        "role": "user",
        "content": "what is the meaning of the universe? 1234"
        }],
    "priority": 0 👈 SET VALUE HERE
}'
import openai
client = openai.OpenAI(
    api_key="anything",
    base_url="http://0.0.0.0:4000"
)

# request sent to model set on litellm proxy, `litellm --model`
response = client.chat.completions.create(
    model="gpt-5.6-luna",
    messages = [
        {
            "role": "user",
            "content": "this is a test request, write a short poem"
        }
    ],
    extra_body={ 
        "priority": 0 # 👈 SET VALUE HERE
    }
)

print(response)

고급 - Redis 캐싱

Redis 캐싱을 사용해 여러 LiteLLM 인스턴스에 걸쳐 요청 우선순위화를 수행해요.

SDK

from litellm import Router

router = Router(
    model_list=[
        {
            "model_name": "gpt-5.6-luna",
            "litellm_params": {
                "model": "gpt-5.6-luna",
                "mock_response": "Hello world this is Macintosh!", # fakes the LLM API call
                "rpm": 1,
            },
        },
    ],
    ### REDIS PARAMS ###
    redis_host=os.environ["REDIS_HOST"], 
    redis_password=os.environ["REDIS_PASSWORD"], 
    redis_port=os.environ["REDIS_PORT"], 
)

try:
    _response = await router.acompletion( # 👈 ADDS TO QUEUE + POLLS + MAKES CALL
        model="gpt-5.6-luna",
        messages=[{"role": "user", "content": "Hey!"}],
        priority=0, # 👈 LOWER IS BETTER
    )
except Exception as e:
    print("didn't make request")

프록시

model_list:
    - model_name: gpt-3.5-turbo-fake-model
      litellm_params:
        model: gpt-5.6-luna
        mock_response: "hello world!" 
        api_key: my-good-key

litellm_settings:
    request_timeout: 600 # 👈 Will keep retrying until timeout occurs

router_settings:
    redis_host: os.environ/REDIS_HOST
    redis_password: os.environ/REDIS_PASSWORD
    redis_port: os.environ/REDIS_PORT
$ litellm --config /path/to/config.yaml 

# RUNNING on http://0.0.0.0:4000s
curl -X POST 'http://localhost:4000/queue/chat/completions' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ***" \
-D '{
    "model": "gpt-3.5-turbo-fake-model",
    "messages": [
        {
        "role": "user",
        "content": "what is the meaning of the universe? 1234"
        }],
    "priority": 0 👈 SET VALUE HERE
}'

더 알아보기 (Learn more)