Skip to main content

Deploy a serving endpoint with the CLI and bundles

Use the Databricks CLI to create, check, update, and delete a Model Serving endpoint, or to deploy one endpoint from a bundle.

The CLI steps use databricks serving-endpoints commands. The bundle steps define an endpoint in a databricks.yml file, and databricks bundle deploy creates or updates it. The examples create two endpoints, cli-endpoint and bundle-endpoint, and both can exist at the same time. To create an endpoint in the Serving UI or with the REST API, see Create an endpoint for custom models in Model Serving.

Requirements​

  • Databricks CLI, v0.218.0 or above for the bundle steps. To install it, see Install or update the Databricks CLI.
  • A custom model registered in Unity Catalog. Unity Catalog requires a signature on each new model version. The examples serve version 1 of <catalog>.<schema>.cli_model. Replace <catalog> and <schema> with your catalog and schema.
  • Signed in to the workspace from the CLI with databricks auth login. Add --profile <name> to use another profile.
  • jq, which the get commands pipe through.

Create an endpoint with the CLI​

Check the CLI version​

Run the following command:

Bash
databricks version

The command prints the installed version, such as Databricks CLI v1.17.0.

Save the endpoint settings​

Save the endpoint settings in create.json:

JSON
{
"name": "cli-endpoint",
"config": {
"served_entities": [
{
"name": "cli-example",
"entity_name": "<catalog>.<schema>.cli_model",
"entity_version": "1",
"workload_size": "Small",
"scale_to_zero_enabled": true
}
],
"traffic_config": {
"routes": [
{
"served_entity_name": "cli-example",
"traffic_percentage": 100
}
]
}
}
}

With --json, the body holds name at the top level, and config holds served_entities and traffic_config. The entity_name is the full name of a Unity Catalog model, and entity_version is given as a string. The endpoint name can use alphanumeric characters, dashes, and underscores, must start and end with a letter or digit, and can't be longer than 63 characters on create.

Create the endpoint​

Run the following command:

Bash
databricks serving-endpoints create --json @create.json

The command prints the endpoint as JSON. When it returns, ready is READY and config_update is NOT_UPDATING. Without --no-wait, the command returns when config_update reaches NOT_UPDATING, and the default timeout is 20 minutes. To return before the endpoint is ready, add --no-wait, and the command returns while config_update is IN_PROGRESS and ready is NOT_READY.

Check the endpoint with the CLI​

Read the endpoint state by running:

Bash
databricks serving-endpoints get cli-endpoint -o json | jq "{ready: .state.ready, config_update: .state.config_update, config_version: .config.config_version}"

The command prints the following.

Text
{
"ready": "READY",
"config_update": "NOT_UPDATING",
"config_version": 1
}

The config_update field takes NOT_UPDATING, IN_PROGRESS, UPDATE_FAILED, or UPDATE_CANCELED. For a new endpoint, ready is NOT_READY until its deployment finishes, and READY after that. During an update to a running endpoint, ready stays READY. When an update finishes successfully, config_update returns to NOT_UPDATING at the same time that ready is READY. The config_version field is the number of the active configuration.

A READY endpoint can still return a 404 to a query for a short time. The error reads The given endpoint is not ready to serve traffic yet, please retry later. No field that get returns shows the state behind that 404, so READY doesn't show whether the next query is accepted.

Update the endpoint with the CLI​

Save the new settings​

Save the new settings in update.json:

JSON
{
"served_entities": [
{
"name": "cli-example",
"entity_name": "<catalog>.<schema>.cli_model",
"entity_version": "1",
"workload_size": "Small",
"scale_to_zero_enabled": false
}
],
"traffic_config": {
"routes": [
{
"served_entity_name": "cli-example",
"traffic_percentage": 100
}
]
}
}

This body has served_entities and traffic_config at the top level, and it has no name and no config object. If you send name or a config object, the CLI warns that it doesn't know those fields, and the update exits with an error, so leave them out.

Update the endpoint​

Run the following command:

Bash
databricks serving-endpoints update-config cli-endpoint --json @update.json

The command returns when config_update reaches NOT_UPDATING.

Read the endpoint after the update​

Run the following command:

Bash
databricks serving-endpoints get cli-endpoint -o json | jq "{ready: .state.ready, config_update: .state.config_update, config_version: .config.config_version, scale_to_zero: [.config.served_entities[].scale_to_zero_enabled]}"

The command prints the following.

Text
{
"ready": "READY",
"config_update": "NOT_UPDATING",
"config_version": 2,
"scale_to_zero": [
false
]
}

The config_version is 2, and scale_to_zero shows false, the value in update.json. While the update runs, config_update shows IN_PROGRESS, and config_version keeps the old number. The old configuration keeps serving until the new one is ready.

Delete the endpoint with the CLI​

Delete the endpoint​

Run the following command:

Bash
databricks serving-endpoints delete cli-endpoint

A successful delete returns no output and exit code 0.

Check that the endpoint is gone​

Run the following command:

Bash
databricks serving-endpoints get cli-endpoint

The command prints the following.

Text
Error: Endpoint with name 'cli-endpoint' does not exist.

The command exits with code 1 and this error, which means the endpoint is gone. Deleting an endpoint can't be undone.

Deploy an endpoint from a bundle​

Declarative Automation Bundles (formerly known as Databricks Asset Bundles) are a feature of the Databricks CLI. The bundle commands start with databricks bundle.

Write the bundle file​

Write the bundle file as databricks.yml:

YAML
bundle:
name: cli-bundles-example

targets:
dev:
default: true
workspace:
host: <workspace-url>

resources:
model_serving_endpoints:
cli_example:
name: bundle-endpoint
config:
served_entities:
- name: cli-example
entity_name: <catalog>.<schema>.cli_model
entity_version: '1'
workload_size: Small
scale_to_zero_enabled: true
traffic_config:
routes:
- served_entity_name: cli-example
traffic_percentage: 100

Replace <workspace-url> with your workspace URL. The targets block holds named targets. The examples use one target, dev, and set it as the default with default: true. The endpoint goes under model_serving_endpoints, and the key, cli_example here, names the resource in the deploy output. The name is the endpoint name, and it must be unique across the workspace.

Each served entity has fields such as entity_name, entity_version, workload_size, and scale_to_zero_enabled. The workload_size field takes Small, Medium, or Large. Don't set it together with min or max provisioned concurrency. For those settings, see Create an endpoint for custom models in Model Serving. In this file, each route names its served entity with served_entity_name, and the traffic_percentage values must total 100.

Validate the bundle​

Run the following command:

Bash
databricks bundle validate --target dev

The command prints the following.

Text
Name: cli-bundles-example
Target: dev
Workspace:
Host: <workspace-url>
User: <user>
Path: /Workspace/Users/<user>/.bundle/cli-bundles-example/dev

Validation OK!

The command checks the bundle, and the output ends with Validation OK!. To treat warnings as errors, add --strict, which needs CLI v0.286.0 or above.

Deploy the bundle​

Run the following command:

Bash
databricks bundle deploy --target dev

The command prints the following.

Text
Uploading bundle files to /Workspace/Users/<user>/.bundle/cli-bundles-example/dev/files...
Created model_serving_endpoints.cli_example
Files: 1 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged

The deploy returns after ready is READY and config_update is NOT_UPDATING, and its output doesn't show that it is waiting.

After the deploy, read the state with the get command in Check the endpoint with the CLI, using bundle-endpoint. The first deploy leaves ready READY, config_update NOT_UPDATING, and config_version 1. With mode: development set on the target, the resolved name is dev_<user>_bundle-endpoint.

Update or destroy a bundle endpoint​

Change the bundle and deploy again​

Change scale_to_zero_enabled from true to false in databricks.yml, and deploy again:

Bash
databricks bundle deploy --target dev

The command prints the following.

Text
Uploading bundle files to /Workspace/Users/<user>/.bundle/cli-bundles-example/dev/files...
Updated model_serving_endpoints.cli_example
Files: 1 uploaded, 0 deleted
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged

The deploy returns when config_update reaches NOT_UPDATING. An update can fail. See An update fails during a bundle deploy. A failed update still uses a config version number, so the next successful update can skip one.

Destroy the bundle​

Run the following command:

Bash
databricks bundle destroy --target dev --auto-approve

The command removes the resources that the bundle created. The --auto-approve flag skips the interactive approval for deleting the bundle's resources and files. To approve the deletion yourself, run the command without the flag in a terminal.

The last lines of its output are the following.

Text
The following resources will be deleted:
delete resources.model_serving_endpoints.cli_example

All files and directories at the following location will be deleted: /Workspace/Users/<user>/.bundle/cli-bundles-example/dev

Destroy: 1 deleted

Check that the bundle endpoint is gone​

Run the following command:

Bash
databricks serving-endpoints get bundle-endpoint

The command prints the following, which says the endpoint does not exist.

Text
Error: Endpoint with name 'bundle-endpoint' does not exist.

Troubleshooting​

The name is passed as an argument with --json​

The command exits with code 1 and prints this error.

Text
Error: when --json flag is specified, no positional arguments are allowed. Provide 'name' in your JSON input

Cause: The CLI rejects a name argument when --json is set, and no endpoint is created.

Solution: Remove the name argument, and put the name in the JSON body, as the create body above does. The create command then returns the endpoint named cli-endpoint.

An update fails during a bundle deploy​

The deploy exits with an error after it waits. The error says the endpoint failed to reach NOT_UPDATING, and that the current status is UPDATE_FAILED.

Cause: The update didn't finish, so config_update shows UPDATE_FAILED, and the active configuration keeps serving.

Solution: Run the same deploy again. To read the message that the failed update left, look at pending_config in the output of databricks serving-endpoints get bundle-endpoint -o json. pending_config holds the version that the failed update was applying. The message says to try updating the endpoint, and to contact Databricks support if the problem persists. When the deploy succeeds, it prints Updated model_serving_endpoints.cli_example, and config_update returns to NOT_UPDATING.

Additional resources​