F5 AI Gateway 모델 기반 라우팅 구성 가이드

F5 AI Gateway 는 다중 모델 서비스를 운영할 수 있는 구조를 제공하며, 요청에 포함된 모델 정보에 따라 요청을 특정 LLM 모델로 라우팅할 수 있습니다. 이 포스트는 클라이언트 요청의 model 필드 값을 기준으로 요청을 라우팅하는 모델 기반 라우팅 설정 방법을 다룹니다.

이 가이드는 Open WebUI를 통해 요청을 전송하고, Ollama를 백엔드 LLM 서비스로 사용하는 구조를 기반으로 합니다.
Open WebUI와 Ollama의 연동 및 설정 방법은 다음 포스트를 참고하세요.

목차

1. 환경 및 버전 정보
2. F5 AI Gateway 모델 기반 라우팅 이해
3. Open WebUI의 모델 선택 및 Ollama 다중 모델 구성
4. F5 AI Gateway 모델 기반 라우팅 설정 및 동작 확인
5. 결론

1. 환경 및 버전 정보

  • Kubernetes: v1.32.2
  • NGINX Plus Ingress Controller: 5.0.0
  • F5 AI Gateway: v1.0.2
  • F5 AI Gateway Helm chart: aigw-0.1.1
  • Open WebUI: v0.6.7
  • Ollama: 0.6.5

2. F5 AI Gateway 모델 기반 라우팅 이해

F5 AI Gateway는 하나의 엔드포인트로 다양한 LLM 모델을 호출할 수 있도록 profileselector 기능을 제공합니다. selector.type: input.model을 활용하면 클라이언트가 전송한 요청의 데이터 안의 "model" 값을 기준으로 다양한 백엔드 LLM 모델로 요청을 라우팅할 수 있습니다.
클라이언트는 요청 전송 시 다음과 같이 모델을 지정하여 요청을 전송할 수 있습니다.

$ curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-4.1",
    "messages": [
      {
        "role": "user",
        "content": "Hello!"
      }
    ]
  }'

F5 AI Gateway의 모델 기반 라우팅을 하기 위한 설정을 다음과 같이 구성할 수 있습니다.

profiles:
  - name: chat-profile
    models:
      - name: hermes
      - name: tiny
    services:
      - name: ollama/hermes
        selector:
          type: input.model
          values:
            - hermes
      - name: ollama/tinyllama
        selector:
          type: input.model
          values:
            - tiny
            
services:
  - name: ollama/hermes
    type: hermes3:8b
    executor: ollama
    config:
      endpoint: "http://192.168.200.129:11434/api/chat"
  - name: ollama/tinyllama
    type: tinyllama:1.1b
    executor: ollama
    config:
      endpoint: "http://192.168.200.129:11434/api/chat"

profiles.models.name 항목은 클라이언트가 사용할 수 있는 모델의 이름을 정의합니다. 이 값은 /v1/models API 요청 시 반환되는 모델 목록에 표시되며, Open WebUI 등의 클라이언트는 이 목록을 기반으로 사용자가 선택할 수 있는 옵션을 구성합니다.

models.name 항목은 사용자에게 노출되는 이름일 뿐, 실제 백엔드 모델 실행과는 직접적인 관련이 없습니다.

profiles:
  - name: chat-profile
    models:
      - name: hermes
      - name: tiny

클라이언트가 요청 본문(JSON)에 포함한 model 값은 selector를 통해 라우팅 조건으로 활용됩니다. 아래 예시에서는 input.model 값을 기준으로 요청을 분기합니다.

services:
  - name: ollama/hermes
    selector:
      type: input.model
      values:
        - hermes
  - name: ollama/tinyllama
    selector:
      type: input.model
      values:
        - tiny

위 구성은 클라이언트 요청 본문의 "model": "hermes" 혹은 "model": "tiny" 값에 따라 각각 ollama/hermes, ollama/tinyllama 서비스로 요청을 전달합니다.

services 항목의 type 필드는 실제 백엔드 실행 환경(Ollama 등)에서 사용할 모델의 정확한 이름(태그)을 명시합니다. 이 값은 Ollama에서 모델 구동 시 표시되는 이름과 정확히 일치해야 합니다.

services:
  - name: ollama/hermes
    type: hermes3:8b
    executor: ollama
    config:
      endpoint: "http://192.168.200.129:11434/api/chat"
  - name: ollama/tinyllama
    type: tinyllama:1.1b
    executor: ollama
    config:
      endpoint: "http://192.168.200.129:11434/api/chat"

클라이언트의 "model": "hermes" 요청은 다음과 같은 흐름으로 처리됩니다:

  1. input.model == "hermes"ollama/hermes 서비스 선택
  2. 해당 서비스의 type == hermes3:8b → Ollama에서 해당 모델로 요청 수행
주의 사항
  • 위와 같이 모델 기반 라우팅 설정 구성 시 클라이언트는 반드시 요청에 model 값을 포함해야 합니다.
  • 클라이언트가 전송한 요청의 model 값이 profiles.models.name에 명시된 값과 일치하지 않으면 404 Model not found 오류가 발생합니다.

3. Open WebUI의 모델 선택 및 Ollama 다중 모델 구성

Open WebUI는 사용자가 요청을 전송하기 전, 모델을 선택하도록 구성되어 있습니다. 선택된 모델은 요청 본문에 포함되어 전달됩니다.

Open WebUI는 모델 선택 메뉴의 리스트를 구성하기 위해 연결된 LLM 백엔드(F5 AI Gateway)의 /v1/models 엔드포인트를 조회합니다.

F5 AI Gateway 모델 조회

F5 AI Gateway의 /v1/models 엔드포인트로 curl 요청을 보내면, 현재 AI Gateway의 profiles에 등록된 모델 목록이 JSON 형식으로 반환됩니다. Open WebUI는 이 정보를 활용해 사용자에게 선택할 수 있는 모델 목록을 제공합니다.

Ollama는 하나의 인스턴스에서 여러 모델을 동시에 로드하고 운영할 수 있습니다.
이를 통해 F5 AI Gateway의 여러 서비스(service) 항목에 각각의 모델을 연결하는 것이 가능합니다.

구동 중인 모델 목록은 Ollama의 /api/tags 엔드포인트를 통해 확인할 수 있습니다.

4. F5 AI Gateway 모델 기반 라우팅 설정 및 동작 확인

F5 AI Gateway 모델 기반 라우팅 설정을 적용합니다. 앞서 제공한 예시 설정을 기반으로 구성했습니다.

version: 1

server:
  address: :4141

logging:
  level: debug

routes:
  - path: /v1/chat/completions
    policy: chat-policy
    schema: v1/chat_completions  
    timeoutSeconds: 240
  - path: /v1/models
    policy: chat-policy
    schema: v1/models

policies:
  - name: chat-policy
    profiles:
      - name: chat-profile

profiles:
  - name: chat-profile
    models:
      - name: hermes
      - name: tiny
    services:
      - name: ollama/hermes
        selector:
          type: input.model
          values:
            - hermes
      - name: ollama/tinyllama
        selector:
          type: input.model
          values:
            - tiny

services:
  - name: ollama/hermes
    type: hermes3:8b
    executor: ollama
    config:
      endpoint: "http://192.168.200.129:11434/api/chat"
  - name: ollama/tinyllama
    type: tinyllama:1.1b
    executor: ollama
    config:
      endpoint: "http://192.168.200.129:11434/api/chat"

F5 AI Gateway 설정 방법에 대한 더 자세한 내용은 F5 AI Gateway 설정 기초 가이드를 참고하세요.

Open WebUI에서 hermes 모델을 선택하고 요청을 전송하면 F5 AI Gateway Pod에서 다음과 같은 로그를 확인할 수 있습니다.

F5 AI Gateway 모델 라우팅 - Open Web UI
F5 AI Gateway 모델 라우팅 - F5 AI Gateway 로그

지정한 모델을 기반으로 upstream(service)를 지정하여 요청을 라우팅하는 것을 확인할 수 있습니다.

Postman을 사용해 AI Gateway로 요청을 전송하고 응답을 확인하겠습니다.

F5 AI Gateway tinyllama 모델 요청
F5 AI Gateway tinyllama 모델 요청 로그

응답과 로그의 id 값이 동일함을 확인할 수 있고, tiny 모델 요청이 F5 AI Gateway의 설정에 따라 Ollama의 tinyllama 모델을 통해 응답하는 것을 확인할 수 있습니다.

F5 AI Gateway hermes 모델 요청
F5 AI Gateway hermes 모델 요청 로그

hermes 모델로의 요청도 동일하게 확인할 수 있습니다.

5. 결론

이번 포스트에서 클라이언트 요청의 model 필드 값을 기준으로 요청을 라우팅하는 모델 기반 라우팅 설정 방법을 알아봤습니다.

F5 AI Gateway의 selector 기능은 다양한 조건 기반 라우팅을 지원하며, 특히 input.model 기반 설정은 다중 모델 환경에서 유용하게 활용될 수 있습니다.
하지만, Open WebUI와 같이 "model" 필드가 클라이언트 요청에 항상 포함되는 구조에서는 라우팅 조건을 정확히 일치시켜야 하며, 누락 시 오류가 발생할 수 있어 주의가 필요합니다.

운영 중인 AI 서비스에 강력한 보안, 모델 기반 라우팅과 같은 기능이 필요하신가요? NGINX STORE를 통해 문의하여 F5 AI Gateway with NGINX Integration 서비스를 통해 AI 서비스를 보호하세요.

NGINX STORE를 통한 솔루션 도입 및 기술지원 무료 상담 신청

* indicates required