|
| 1 | +--- |
| 2 | +title: Endpoints |
| 3 | +description: Creating and reusing optimized model inference recipes |
| 4 | +--- |
| 5 | + |
| 6 | +# Endpoints |
| 7 | + |
| 8 | +An endpoint configuration is a new `dstack` feature that lets you use an agent to create presets: validated and optimized model inference endpoint recipes. Once a preset is created, it can be reused to deploy model inference on validated hardware without an agent. |
| 9 | + |
| 10 | +The value of presets comes from combining two fundamental features: agent-driven model inference optimization and the `dstack` [service](services.md) primitive, which can deploy model inference to any cloud, Kubernetes, or on-prem cluster. |
| 11 | + |
| 12 | +> The endpoints feature is experimental and may change. |
| 13 | +
|
| 14 | +??? info "Prerequisites" |
| 15 | + Before using endpoint presets, make sure you’ve [installed](../installation.md) the server and CLI, and created a [fleet](fleets.md). |
| 16 | + |
| 17 | + Creating an endpoint preset requires the `claude` CLI to be installed on the machine where you create a preset. |
| 18 | + |
| 19 | +## Define an endpoint |
| 20 | + |
| 21 | +Before you can create or reuse an endpoint preset, you first have to define an endpoint configuration. The filename must end with `.dstack.yml`. |
| 22 | + |
| 23 | +<div editor-title="endpoint.dstack.yml"> |
| 24 | + |
| 25 | +```yaml |
| 26 | +type: endpoint |
| 27 | +name: qwen25-7b |
| 28 | + |
| 29 | +model: |
| 30 | + base: Qwen/Qwen2.5-7B-Instruct |
| 31 | + |
| 32 | +env: |
| 33 | + - HF_TOKEN |
| 34 | +``` |
| 35 | +
|
| 36 | +</div> |
| 37 | +
|
| 38 | +Since `base` is specified, the preset can use any compatible variant of the base model, including a different precision, quantization, or trusted fork. |
| 39 | + |
| 40 | +If you want to deploy an exact model, set `model` directly to the repo of that model: |
| 41 | + |
| 42 | +<div editor-title="endpoint.dstack.yml"> |
| 43 | + |
| 44 | +```yaml |
| 45 | +type: endpoint |
| 46 | +name: qwen25-7b |
| 47 | +
|
| 48 | +model: Qwen/Qwen2.5-7B-Instruct |
| 49 | +
|
| 50 | +env: |
| 51 | + - HF_TOKEN |
| 52 | +``` |
| 53 | + |
| 54 | +</div> |
| 55 | + |
| 56 | +Set `context_length` to require a minimum context length. Placement properties, |
| 57 | +including `fleets`, `backends`, `max_price`, and `spot_policy`, constrain both |
| 58 | +creation and reuse. Environment variables such as `HF_TOKEN` can be passed |
| 59 | +through `env`. |
| 60 | + |
| 61 | +See the [reference](../reference/dstack.yml/endpoint.md) for all supported configuration options. |
| 62 | + |
| 63 | +## Create a preset |
| 64 | + |
| 65 | +To create a preset, pass the configuration file to the `dstack endpoint preset create` command: |
| 66 | + |
| 67 | +<div class="termy"> |
| 68 | + |
| 69 | +```shell |
| 70 | +$ dstack endpoint preset create -f endpoint.dstack.yml |
| 71 | +``` |
| 72 | + |
| 73 | +</div> |
| 74 | + |
| 75 | +This command executes entirely locally and uses the locally installed `claude` CLI along with `dstack`'s bundled skills. The agent uses a `dstack` task to find the best serving recipe matching the available fleet offers. Once the recipe is found, it submits a `dstack` service for a final benchmark. The validated recipe is saved locally under `~/.dstack/presets`. |
| 76 | + |
| 77 | +??? info "Claude authorization" |
| 78 | + Preset creation supports two Claude authorization methods. To use an Anthropic API key, set: |
| 79 | + |
| 80 | + ```shell |
| 81 | + export DSTACK_AGENT_ANTHROPIC_API_KEY=... |
| 82 | + ``` |
| 83 | + |
| 84 | + If you are already logged in with `claude`, use the existing authorization instead: |
| 85 | + |
| 86 | + ```shell |
| 87 | + export DSTACK_AGENT_CLAUDE_USE_EXISTING_AUTH=1 |
| 88 | + ``` |
| 89 | + |
| 90 | + These options are mutually exclusive. |
| 91 | + |
| 92 | +## List presets |
| 93 | + |
| 94 | +Use `dstack endpoint preset` to list existing presets: |
| 95 | + |
| 96 | +<div class="termy"> |
| 97 | + |
| 98 | +```shell |
| 99 | +$ dstack endpoint preset list |
| 100 | + MODEL GPU |
| 101 | + Qwen/Qwen2.5-7B-Instruct |
| 102 | + recipe=8f3a12c4 L4:24GB:1.. |
| 103 | +``` |
| 104 | + |
| 105 | +</div> |
| 106 | + |
| 107 | +Each base model corresponds to one preset. A preset may contain multiple recipes built for specific hardware. Each recipe includes benchmark data. |
| 108 | + |
| 109 | +Pass `-v` to include the full service resources and verified context length. |
| 110 | + |
| 111 | +## Apply a preset |
| 112 | + |
| 113 | +To deploy a preset as a service, pass the endpoint configuration to the `dstack endpoint preset apply` command: |
| 114 | + |
| 115 | +<div class="termy"> |
| 116 | + |
| 117 | +```shell |
| 118 | +$ dstack endpoint preset apply -f endpoint.dstack.yml |
| 119 | +``` |
| 120 | + |
| 121 | +</div> |
| 122 | + |
| 123 | +If you don't pass `--recipe ID` (or specify it in the endpoint configuration), `dstack` automatically picks one of the recipes that matches the available fleet offers. |
| 124 | + |
| 125 | +If a recipe matches, `dstack` deploys it as a service. |
| 126 | + |
| 127 | +## Delete a preset |
| 128 | + |
| 129 | +You can delete a specific recipe or the entire preset. |
| 130 | + |
| 131 | +<div class="termy"> |
| 132 | + |
| 133 | +```shell |
| 134 | +dstack endpoint preset delete --recipe 8f3a12c4 |
| 135 | +``` |
| 136 | + |
| 137 | +</div> |
| 138 | + |
| 139 | +To delete the entire preset and all its recipes, pass the base model: |
| 140 | + |
| 141 | +<div class="termy"> |
| 142 | + |
| 143 | +```shell |
| 144 | +dstack endpoint preset delete Qwen/Qwen2.5-7B-Instruct |
| 145 | +``` |
| 146 | + |
| 147 | +</div> |
| 148 | + |
| 149 | +For command options and agent settings, see the |
| 150 | +[`dstack endpoint` CLI reference](../reference/cli/dstack/endpoint.md). |
| 151 | + |
| 152 | +!!! info "What's next?" |
| 153 | + 1. Learn how dstack [services](services.md) work |
| 154 | + 2. Learn how to configure [fleets](fleets.md) |
0 commit comments