Tutorial: Deploy and query a custom model

This article provides the basic steps for deploying and querying a custom model, that is a traditional ML model, installed in Unity Catalog or registered in the workspace model registry using Databricks model serving.

The following are guides that describe serving and deploying a foundation model for generative AI and LLM:

Step 1: Log the model to the model registry

There are different ways to log your model for model serving:

Logging technique



This is automatically turned on when you use Databricks Runtime for machine learning. It’s the easiest way but gives you less control.

Logging using MLflow’s built-in flavors

You can manually log the model with MLflow’s built-in model flavors.

Custom logging with pyfunc

Use this if you have a custom model or if you need extra steps before or after inference.

The following example shows how to log your MLflow model using the transformer flavor and specify parameters you need for your model.

with mlflow.start_run():
    model_info = mlflow.transformers.log_model(

After your model is logged be sure to check that your model is registered in either the MLflow Unity Catalog or Model Registry.

Step 2: Create endpoint using the Serving UI

After your registered model is logged and you are ready to serve it, you can create a model serving endpoint using the Serving UI.

  1. Click Serving in the sidebar to display the Serving UI.

  2. Click Create serving endpoint.

    Model serving pane in Databricks UI
  3. In the Name field, provide a name for your endpoint.

  4. In the Served entities section

    1. Click into the Entity field to open the Select served entity form.

    2. Select the type of model you want to serve. 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. Support for model serving on GPU is in Public Preview. See GPU workload types for more information on available GPU computes.

    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. This number should be roughly equal to QPS x model execution time.

      1. Available sizes are Small for 0-4 requests, Medium 8-16 requests, and Large for 16-64 requests.

    7. Specify if the endpoint should scale to zero when not in use.

  5. Click Create. The Serving endpoints page appears with Serving endpoint state shown as Not Ready.

    Create a model serving endpoint

If you prefer to create an endpoint programmatically with the Databricks Serving API, see Create custom model serving endpoints.

Step 3: Query the endpoint

The easiest and fastest way to test and send scoring requests to your served model is to use the Serving UI.

  1. From the Serving endpoint page, select Query endpoint.

  2. Insert the model input data in JSON format and click Send Request. If the model has been logged with an input example, click Show Example to load the input example.

       "inputs" : ["Hello, I'm a language model,"],
       "params" : {"max_new_tokens": 10, "temperature": 1}

To send scoring requests, construct a JSON with one of the supported keys and a JSON object corresponding to the input format. See Query serving endpoints for custom models for supported formats and guidance on how to send scoring requests using the API.

If you plan to access your serving endpoint outside of the Databricks Serving UI, you need a DATABRICKS_API_TOKEN.


As a security best practice for production scenarios, Databricks recommends that you use machine-to-machine OAuth tokens for authentication during production.

For testing and development, Databricks recommends using a personal access token belonging to service principals instead of workspace users. To create tokens for service principals, see Manage tokens for a service principal.

Example notebooks

See the following notebook for serving a MLflow transformers model with Model Serving.

Deploy a Hugging Face transformers model notebook

Open notebook in new tab

See the following notebook for serving a MLflow pyfunc model with Model Serving. For additional details on customizing your model deployments, see Deploy Python code with Model Serving.

Deploy a MLflow pyfunc model notebook

Open notebook in new tab