Sub topic 8
Creating an endpoint for a registered model
This chapter assumes you have a model registered in Unity Catalog (for example main.default.iris_classifier, version 1) and that you can run Python in a Databricks notebook. Earlier chapters covered the signature, versions, aliases, and privileges.
What you are creating
A serving endpoint is a managed REST service that loads one or more model versions and answers scoring requests. Databricks builds the container, provisions the compute, and exposes an HTTPS URL. You choose the model, the version, and the compute size.
Check the prerequisites first
Most creation failures come from missing prerequisites, not from the create call itself.
- The model has a signature. Unity Catalog requires one at registration, and the endpoint uses it to validate requests.
- You know the exact version number. The served entity takes a version, not an alias.
- You hold
USE CATALOGon the catalog,USE SCHEMAon the schema, andEXECUTEon the model. - The endpoint name is unique in the workspace. Use letters, digits, dashes, and underscores.
Create the endpoint with the SDK
The Databricks SDK for Python describes the endpoint as a configuration with one or more served entities. Each served entity points to a model version.
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import EndpointCoreConfigInput, ServedEntityInput
w = WorkspaceClient()
w.serving_endpoints.create_and_wait(
name="iris-endpoint",
config=EndpointCoreConfigInput(
served_entities=[
ServedEntityInput(
entity_name="main.default.iris_classifier",
entity_version="1",
workload_size="Small",
scale_to_zero_enabled=True,
)
]
),
)The fields work as follows:
| Field | Meaning |
|---|---|
| `name` | The endpoint name. It becomes part of the URL. |
| `entity_name` | The full three-level model name. |
| `entity_version` | The version to serve, passed as a string. |
| `workload_size` | How much concurrency the endpoint can handle. |
| `scale_to_zero_enabled` | Lets the endpoint shut down compute when idle. |
The next chapter covers the last two fields in detail. For now, Small with scale to zero is a reasonable starting point for testing.
Why create_and_wait
create returns immediately while Databricks builds the model container and starts the compute, which usually takes several minutes. create_and_wait blocks until the endpoint reaches a ready state or fails. It returns the endpoint details, so you can inspect the result.
endpoint = w.serving_endpoints.get("iris-endpoint")
print(endpoint.state.ready)
print(endpoint.state.config_update)A healthy endpoint reports READY and NOT_UPDATING. If the build fails, the wait call raises an error, and the endpoint's event logs in the workspace UI show the cause.
Common errors
- Permission denied on the model. You lack
EXECUTEon the model, orUSE CATALOGorUSE SCHEMAon its parents. Grant all three. - Endpoint name already exists. Names are unique per workspace. Pick another name or update the existing endpoint.
- Model not found. Check the three-level name and that the version exists. A typo in
entity_versionproduces the same error. - Build failure. The model's dependencies may not install, for example when
requirements.txtpins a package version that is unavailable. Check the build logs, then re-log the model with corrected requirements and register a new version.
Check your understanding
Exercise
You registered a model and set the alias champion on version 3. You create an endpoint with entity_name="main.default.iris_classifier" and entity_version="3". Next week you move champion to version 4. Which version does the endpoint serve, and why?
Show answer
It still serves version 3. The served entity is pinned to the version number you passed at creation. Aliases are not tracked by the endpoint, so you must update the endpoint configuration to serve version 4.
Exercise
create_and_wait fails with a permission error even though you own the endpoint name. Name three privileges to check.
Show answer
USE CATALOG on the catalog, USE SCHEMA on the schema, and EXECUTE on the registered model.