docker model gateway
docker model gateway
docker model gateway 명령은 OpenAI 호환 LLM 게이트웨이를 실행합니다.
출처: 문서
본문
docker model gateway는 하나 이상의 구성된 LLM 공급자로 요청을 라우팅하는 로컬 OpenAI 호환 HTTP 게이트웨이를 띄워요. Docker Model Runner를 일급 공급자로 지원하며, Ollama·OpenAI·Anthropic·Groq·Mistral·Azure OpenAI 등 다양한 OpenAI 호환 엔드포인트를 함께 사용할 수 있어요.
게이트웨이는 모델 목록, 공급자 라우팅, 로드 밸런싱, 재시도, 폴백을 선언하는 YAML 파일로 구성돼요.
구성 파일 형식 (Configuration file format)
model_list:
- model_name: <클라이언트에 노출되는 별칭>
params:
model: <provider>/<업스트림-모델명>
api_base: <선택적 기본 URL 오버라이드>
api_key: <선택적 키 또는 os.environ/VAR_NAME>
general_settings:
master_key: <클라이언트가 요구하는 선택적 API 키>
num_retries: <선택적 정수, 기본 0>
fallbacks:
- <primary-alias>: [<fallback-alias>, ...]
params 아래의 model 필드는 provider/model-name 형식을 사용해요. 지원하는 공급자 접두사는 docker_model_runner, openai, anthropic, ollama, groq, mistral, together_ai, deepseek, fireworks_ai, openrouter, perplexity, xai, nvidia_nim, cerebras, sambanova, deepinfra, azure, azure_ai, vllm, lm_studio, huggingface 예요.
API 키는 인라인으로, os.environ/VAR_NAME 참조로, 또는 ${VAR_NAME} 참조로 제공할 수 있어요. 게이트웨이는 잘 알려진 환경변수(OPENAI_API_KEY, ANTHROPIC_API_KEY 등)를 자동으로 해석해요.
옵션 (Options)
| 옵션 | 기본값 | 설명 |
|---|---|---|
-c, --config |
YAML 구성 파일 경로 | |
--host |
0.0.0.0 |
바인딩할 호스트 주소 |
-p, --port |
4000 |
수신 대기할 포트 |
-v, --verbose |
상세(디버그) 로깅 활성화 |
예시 (Examples)
Docker Model Runner로 요청 라우팅
model_list:
- model_name: smollm2
params:
model: docker_model_runner/ai/smollm2
api_base: http://localhost:12434/engines/llama.cpp/v1
$ docker model gateway --config config.yaml
게이트웨이는 http://0.0.0.0:4000에서 시작돼요. OpenAI 호환 클라이언트를 사용해 요청을 보내면 돼요:
$ curl http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "smollm2",
"messages": [{"role": "user", "content": "Hello"}]
}'
폴백이 있는 여러 공급자로 요청 라우팅
model_list:
- model_name: fast
params:
model: groq/llama-3.1-8b-instant
api_key: os.environ/GROQ_API_KEY
- model_name: smart
params:
model: openai/gpt-4o
api_key: os.environ/OPENAI_API_KEY
- model_name: local
params:
model: docker_model_runner/ai/smollm2
api_base: http://localhost:12434/engines/llama.cpp/v1
general_settings:
num_retries: 2
fallbacks:
- fast: [local]
- smart: [fast, local]
$ docker model gateway --config config.yaml --port 8080
API 키로 게이트웨이 보안 설정
model_list:
- model_name: smollm2
params:
model: docker_model_runner/ai/smollm2
api_base: http://localhost:12434/engines/llama.cpp/v1
general_settings:
master_key: os.environ/GATEWAY_API_KEY
$ GATEWAY_API_KEY=my-secret docker model gateway --config config.yaml
클라이언트는 이제 Bearer 토큰 또는 x-api-key 헤더로 키를 전달해야 해요:
$ curl http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "smollm2", "messages": [{"role": "user", "content": "Hi"}]}'
사용자 정의 호스트와 포트 사용
$ docker model gateway --config config.yaml --host 127.0.0.1 --port 9000
디버그 로깅 활성화
$ docker model gateway --config config.yaml --verbose