|
| 1 | +command: docker model gateway |
| 2 | +short: Run an OpenAI-compatible LLM gateway |
| 3 | +long: |- |
| 4 | + `docker model gateway` starts a local OpenAI-compatible HTTP gateway that routes |
| 5 | + requests to one or more configured LLM providers. It supports Docker Model Runner |
| 6 | + as a first-class provider, alongside Ollama, OpenAI, Anthropic, Groq, Mistral, |
| 7 | + Azure OpenAI, and many other OpenAI-compatible endpoints. |
| 8 | +
|
| 9 | + The gateway is configured through a YAML file that declares the model list, |
| 10 | + provider routing, load-balancing, retries, and fallbacks. |
| 11 | +
|
| 12 | + ### Configuration file format |
| 13 | +
|
| 14 | + ```yaml |
| 15 | + model_list: |
| 16 | + - model_name: <alias exposed to clients> |
| 17 | + params: |
| 18 | + model: <provider>/<upstream-model-name> |
| 19 | + api_base: <optional base URL override> |
| 20 | + api_key: <optional key or os.environ/VAR_NAME> |
| 21 | +
|
| 22 | + general_settings: |
| 23 | + master_key: <optional API key required by clients> |
| 24 | + num_retries: <optional integer, default 0> |
| 25 | + fallbacks: |
| 26 | + - <primary-alias>: [<fallback-alias>, ...] |
| 27 | + ``` |
| 28 | +
|
| 29 | + The `model` field under `params` uses the format `provider/model-name`. |
| 30 | + Supported provider prefixes include: `docker_model_runner`, `openai`, |
| 31 | + `anthropic`, `ollama`, `groq`, `mistral`, `together_ai`, `deepseek`, |
| 32 | + `fireworks_ai`, `openrouter`, `perplexity`, `xai`, `nvidia_nim`, |
| 33 | + `cerebras`, `sambanova`, `deepinfra`, `azure`, `azure_ai`, `vllm`, |
| 34 | + `lm_studio`, `huggingface`. |
| 35 | +
|
| 36 | + API keys can be supplied inline, as `os.environ/VAR_NAME` references, or as |
| 37 | + `${VAR_NAME}` references. The gateway resolves well-known environment variables |
| 38 | + automatically (for example, `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`). |
| 39 | +usage: docker model gateway |
| 40 | +pname: docker model |
| 41 | +plink: docker_model.yaml |
| 42 | +options: |
| 43 | + - option: config |
| 44 | + shorthand: c |
| 45 | + value_type: string |
| 46 | + description: Path to the YAML configuration file |
| 47 | + deprecated: false |
| 48 | + hidden: false |
| 49 | + experimental: false |
| 50 | + experimentalcli: false |
| 51 | + kubernetes: false |
| 52 | + swarm: false |
| 53 | + - option: host |
| 54 | + value_type: string |
| 55 | + default_value: 0.0.0.0 |
| 56 | + description: Host address to bind to |
| 57 | + deprecated: false |
| 58 | + hidden: false |
| 59 | + experimental: false |
| 60 | + experimentalcli: false |
| 61 | + kubernetes: false |
| 62 | + swarm: false |
| 63 | + - option: port |
| 64 | + shorthand: p |
| 65 | + value_type: uint16 |
| 66 | + default_value: "4000" |
| 67 | + description: Port to listen on |
| 68 | + deprecated: false |
| 69 | + hidden: false |
| 70 | + experimental: false |
| 71 | + experimentalcli: false |
| 72 | + kubernetes: false |
| 73 | + swarm: false |
| 74 | + - option: verbose |
| 75 | + shorthand: v |
| 76 | + value_type: bool |
| 77 | + default_value: "false" |
| 78 | + description: Enable verbose (debug) logging |
| 79 | + deprecated: false |
| 80 | + hidden: false |
| 81 | + experimental: false |
| 82 | + experimentalcli: false |
| 83 | + kubernetes: false |
| 84 | + swarm: false |
| 85 | +examples: |- |
| 86 | + ### Route requests to Docker Model Runner |
| 87 | +
|
| 88 | + ```yaml |
| 89 | + model_list: |
| 90 | + - model_name: smollm2 |
| 91 | + params: |
| 92 | + model: docker_model_runner/ai/smollm2 |
| 93 | + api_base: http://localhost:12434/engines/llama.cpp/v1 |
| 94 | + ``` |
| 95 | +
|
| 96 | + ```console |
| 97 | + $ docker model gateway --config config.yaml |
| 98 | + ``` |
| 99 | +
|
| 100 | + The gateway starts on `http://0.0.0.0:4000`. Send requests using any |
| 101 | + OpenAI-compatible client: |
| 102 | +
|
| 103 | + ```console |
| 104 | + $ curl http://localhost:4000/v1/chat/completions \ |
| 105 | + -H "Content-Type: application/json" \ |
| 106 | + -d '{ |
| 107 | + "model": "smollm2", |
| 108 | + "messages": [{"role": "user", "content": "Hello"}] |
| 109 | + }' |
| 110 | + ``` |
| 111 | +
|
| 112 | + ### Route requests to multiple providers with fallback |
| 113 | +
|
| 114 | + ```yaml |
| 115 | + model_list: |
| 116 | + - model_name: fast |
| 117 | + params: |
| 118 | + model: groq/llama-3.1-8b-instant |
| 119 | + api_key: os.environ/GROQ_API_KEY |
| 120 | + - model_name: smart |
| 121 | + params: |
| 122 | + model: openai/gpt-4o |
| 123 | + api_key: os.environ/OPENAI_API_KEY |
| 124 | + - model_name: local |
| 125 | + params: |
| 126 | + model: docker_model_runner/ai/smollm2 |
| 127 | + api_base: http://localhost:12434/engines/llama.cpp/v1 |
| 128 | +
|
| 129 | + general_settings: |
| 130 | + num_retries: 2 |
| 131 | + fallbacks: |
| 132 | + - fast: [local] |
| 133 | + - smart: [fast, local] |
| 134 | + ``` |
| 135 | +
|
| 136 | + ```console |
| 137 | + $ docker model gateway --config config.yaml --port 8080 |
| 138 | + ``` |
| 139 | +
|
| 140 | + ### Secure the gateway with an API key |
| 141 | +
|
| 142 | + ```yaml |
| 143 | + model_list: |
| 144 | + - model_name: smollm2 |
| 145 | + params: |
| 146 | + model: docker_model_runner/ai/smollm2 |
| 147 | + api_base: http://localhost:12434/engines/llama.cpp/v1 |
| 148 | +
|
| 149 | + general_settings: |
| 150 | + master_key: os.environ/GATEWAY_API_KEY |
| 151 | + ``` |
| 152 | +
|
| 153 | + ```console |
| 154 | + $ GATEWAY_API_KEY=my-secret docker model gateway --config config.yaml |
| 155 | + ``` |
| 156 | +
|
| 157 | + Clients must then pass the key as a Bearer token or via the `x-api-key` header: |
| 158 | +
|
| 159 | + ```console |
| 160 | + $ curl http://localhost:4000/v1/chat/completions \ |
| 161 | + -H "Content-Type: application/json" \ |
| 162 | + -d '{"model": "smollm2", "messages": [{"role": "user", "content": "Hi"}]}' |
| 163 | + ``` |
| 164 | +
|
| 165 | + ### Use a custom host and port |
| 166 | +
|
| 167 | + ```console |
| 168 | + $ docker model gateway --config config.yaml --host 127.0.0.1 --port 9000 |
| 169 | + ``` |
| 170 | +
|
| 171 | + ### Enable debug logging |
| 172 | +
|
| 173 | + ```console |
| 174 | + $ docker model gateway --config config.yaml --verbose |
| 175 | + ``` |
| 176 | +deprecated: false |
| 177 | +hidden: false |
| 178 | +experimental: false |
| 179 | +experimentalcli: false |
| 180 | +kubernetes: false |
| 181 | +swarm: false |
| 182 | + |
0 commit comments