Skip to main content

Create an endpoint for custom models in Model Serving

Databricks Model Serving hosts a registered custom model on an endpoint that you query over REST. This page creates one with the MLflow Deployments SDK, then covers the Serving UI, the REST API, and GPU workload types.

Requirements​

Try a notebook example​

The following notebooks include different models registered in Databricks that you can use to get started with model serving endpoints. For additional examples, see Tutorial: Deploy and query a custom model.

To import the model examples into the workspace, follow the directions in Import a notebook. After you choose and create a model from one of the examples, register it in Unity Catalog, and then follow the Serving UI steps for model serving.

Train and register a scikit-learn model for model serving notebook

Train and register a HuggingFace model for model serving notebook

Create an endpoint​

Create the endpoint with one of these methods:

For the Databricks SDK for Python, see serving_endpoints.create in the SDK reference. For foundation models, including external models, see Create foundation model serving endpoints.

Create with the MLflow Deployments SDK​

The MLflow Deployments SDK provides create, update, and delete APIs that accept the same parameters as the REST API.

Install MLflow​

In a Databricks notebook, run the following:

Python
%pip install mlflow

The command finishes without errors. Outside a notebook, run pip install mlflow in a terminal, and set the DATABRICKS_HOST and DATABRICKS_TOKEN environment variables to your workspace URL and an access token. See Authorize access to Databricks resources.

Create the endpoint​

The example serves version 3 of catalog.schema.my-ads-model with custom concurrency, set by min_provisioned_concurrency and max_provisioned_concurrency. Concurrency values must be multiples of 4. See Model Serving limits and regions. Run the following:

Python
import mlflow
from mlflow.deployments import get_deploy_client

mlflow.set_registry_uri("databricks-uc")
client = get_deploy_client("databricks")

endpoint = client.create_endpoint(
name="unity-catalog-model-endpoint",
config={
"served_entities": [
{
"name": "ads-entity",
"entity_name": "catalog.schema.my-ads-model",
"entity_version": "3",
"min_provisioned_concurrency": 4,
"max_provisioned_concurrency": 12,
"scale_to_zero_enabled": False
}
]
}
)

The call returns the endpoint's details, and endpoint["name"] is unity-catalog-model-endpoint.

Wait until the endpoint is ready​

Run the following check again until the output is READY:

Python
endpoint = client.get_endpoint(endpoint="unity-catalog-model-endpoint")
print(endpoint["state"]["ready"])

Until the endpoint is ready, the output is NOT_READY, and the Serving UI shows the endpoint as Not ready.

Create in the Serving UI​

To create an endpoint in the Serving UI, use the steps for your cloud.

For models in Unity Catalog (recommended) or the legacy Workspace Model Registry:

Open the Serving UI​

Select Serving in the sidebar to display the Serving UI. Select Create serving endpoint.

Model serving pane in the workspace UI

Name the endpoint​

In the Name field provide a name for your endpoint. Endpoint names can't use the databricks- prefix. This prefix is reserved for Databricks preconfigured endpoints.

Configure the served entities​

In the Served entities section:

  1. Select the Entity field to open the Select served entity form.
  2. Select either My models - Unity Catalog or My models - Model Registry based on where your model is registered. The form dynamically updates based on your selection.
  3. Select which model and model version you want to serve.
  4. Select the percentage of traffic to route to your served model.
  5. Select what size compute to use. You can use CPU or GPU computes for your workloads. See Compute type for available workload types, including the CPU_MEDIUM and CPU_LARGE options, which are in Beta, for models that need more memory than the standard CPU type. For GPU code examples, see GPU workload types.
  6. Under Compute scale-out, select the size of the compute scale out that corresponds with the number of requests this served model can process at the same time. The value is roughly queries per second (QPS) times model run time. For customer-defined compute settings, see model serving limits.
    1. For the CPU workload type, Small is 4 concurrent requests, Medium is 8-16, and Large is 16-64. For other workload types, the ranges can differ. The Serving UI shows the sizes available for your workload type.
  7. Set whether the endpoint scales to zero when not in use. With scale to zero enabled, each size can scale down to 0. Scale to zero is not recommended for production endpoints, as capacity is not guaranteed when scaled to zero. When an endpoint scales to zero, there is additional latency, also referred to as a cold start, when the endpoint scales back up to serve requests.
  8. Under Advanced configuration, you can:
  9. (Optional) To add additional served entities to your endpoint, select Add served entity and repeat the configuration steps above. To serve multiple models or model versions from a single endpoint and control the traffic split between them, see serve multiple models.

Choose route optimization​

In the Route optimization section, you can enable route optimization for your endpoint. Route optimization is recommended for endpoints with high QPS and throughput requirements. See Route optimization for Model Serving endpoints.

Choose governance features​

Select which governance features to enable on your endpoint. See AI governance with Unity Gateway.

Select Create​

Select Create. The endpoint's page opens, and its status shows Not ready.

Create a model serving endpoint

You can also:

  • Enable inference tables to automatically capture incoming requests and outgoing responses to your model serving endpoints.
  • If you have inference tables enabled on your endpoint, you can log your feature lookup DataFrame to the inference table. The served entity also needs Enable tracing turned on.

You can also add an instance profile or environment variables to store credentials for model serving. See Secrets and credentials for Model Serving endpoints.

Create with the REST API​

You can create endpoints using the REST API. See Create a new serving endpoint for endpoint configuration parameters.

The following example creates an endpoint that serves the third version of the my-ads-model model registered in Unity Catalog. To specify a model from Unity Catalog, provide the full model name including parent catalog and schema, such as catalog.schema.example-model. The example uses the same concurrency settings as the MLflow Deployments SDK example above.

Send this request:

Text
POST /api/2.0/serving-endpoints

With this JSON body:

JSON
{
"name": "uc-model-endpoint",
"config": {
"served_entities": [
{
"name": "ads-entity",
"entity_name": "catalog.schema.my-ads-model",
"entity_version": "3",
"min_provisioned_concurrency": 4,
"max_provisioned_concurrency": 12,
"scale_to_zero_enabled": false
}
]
}
}

The following is an example response. The endpoint's config_update state is NOT_UPDATING and the served model is in a READY state.

JSON
{
"name": "uc-model-endpoint",
"creator": "user@example.com",
"creation_timestamp": 1700089637000,
"last_updated_timestamp": 1700089760000,
"state": {
"ready": "READY",
"config_update": "NOT_UPDATING"
},
"config": {
"served_entities": [
{
"name": "ads-entity",
"entity_name": "catalog.schema.my-ads-model",
"entity_version": "3",
"min_provisioned_concurrency": 4,
"max_provisioned_concurrency": 12,
"scale_to_zero_enabled": false,
"workload_type": "CPU",
"state": {
"deployment": "DEPLOYMENT_READY",
"deployment_state_message": ""
},
"creator": "user@example.com",
"creation_timestamp": 1700089760000
}
],
"config_version": 1
},
"tags": [
{
"key": "team",
"value": "data science"
}
],
"id": "e3bd3e471d6045d6b75f384279e4b6ab",
"permission_level": "CAN_MANAGE",
"route_optimized": false
}

GPU workload types​

GPU deployment is compatible with MLflow 2.4.0 and above. Model Serving installs the versions of cuda and cuDNN that the PyTorch and TensorFlow documentation recommend. See Troubleshoot Model Serving endpoints. To serve a model with the same library versions you trained or tested it with, register it from an AI Runtime notebook as an express deployment. For LLMs, see Deploy a custom LLM with Model Serving.

To create a GPU endpoint with the MLflow Deployments SDK, set workload_type on the served entity to a GPU type from the table below.

Python
import mlflow
from mlflow.deployments import get_deploy_client

mlflow.set_registry_uri("databricks-uc")
client = get_deploy_client("databricks")

endpoint = client.create_endpoint(
name="gpu-model-endpoint",
config={
"served_entities": [{
"entity_name": "catalog.schema.my-gpu-model",
"entity_version": "1",
"workload_type": "GPU_SMALL",
"workload_size": "Small",
"scale_to_zero_enabled": False
}]
}
)

Check the state with the get_endpoint call from the wait step, using the name gpu-model-endpoint.

To use the REST API, include workload_type in the served entity configuration, as in Create with the REST API. In the Serving UI, select a GPU type from the Compute type dropdown when creating your endpoint, as in Create in the Serving UI.

The available GPU workload types depend on your cloud provider, as summarized in the following table. For every workload type, including types in Beta, see Compute type.

GPU workload type

GPU instance

GPU memory

GPU_SMALL

1xT4

16GB

GPU_MEDIUM

1xA10G

24GB

MULTIGPU_MEDIUM

4xA10G

96GB

GPU_MEDIUM_8

8xA10G

192GB

GPU workload type

GPU instance

GPU memory

GPU_SMALL

1xT4

16GB

GPU_MEDIUM

1xA10G

24GB

MULTIGPU_MEDIUM

4xA10G

96GB

GPU_MEDIUM_8

8xA10G

192GB

For GPU endpoints, the concurrency value determines the number of replicas allocated to serve your model. The number of replicas equals the concurrency value divided by 4. For example, setting min_provisioned_concurrency to 12 provisions 3 replicas.

Check the permissions an endpoint needs​

To create or update a model serving endpoint, both the caller and the endpoint's recorded creator must:

  • Be a member of the workspace.
  • Hold the workspace-access entitlement.

Creator identity​

When you create an endpoint, Databricks records the calling identity as the endpoint's creator. This identity, typically a service principal, is used to access Unity Catalog resources on behalf of the endpoint and can't be changed after creation.

If the recorded creator lacks the required Unity Catalog grants or has been removed from the workspace, you must delete the endpoint and recreate it under a service principal that has the required permissions and is a current workspace member.

Configuration and served-entity updates re-evaluate the recorded creator's workspace membership and grants. Updates fail with PERMISSION_DENIED if the recorded creator is no longer a workspace member, even when the caller has valid permissions.

Served entity grants​

The recorded creator must hold the following grants on each served entity. Grants validated at endpoint creation or update cause the request to fail with PERMISSION_DENIED if missing. Grants required at query time are not validated upfront, so missing grants cause runtime errors when the endpoint serves traffic.

Resource type

Required grant

When validated

Unity Catalog model

USE CATALOG on the catalog, USE SCHEMA on the schema, EXECUTE on the model

Endpoint creation or update

Resource type

Required grant

When validated

Unity Catalog model

USE CATALOG on the catalog, USE SCHEMA on the schema, EXECUTE on the model

Endpoint creation or update

note

If a Unity Catalog model declares transitive function dependencies, the recorded creator also needs EXECUTE on those upstream functions.

Manage endpoint access​

To understand access control options for model serving endpoints, see Manage permissions on a model serving endpoint.

Update an endpoint's configuration​

To change an endpoint's served models, compute, or traffic after you create it, see Update an endpoint's configuration in Model Serving.

Score a model endpoint​

To score your model, send requests to the model serving endpoint.

Additional resources​