---
title: Route optimization on serving endpoints
description: Learn how to enable route-optimization on your model serving endpoints.
canonical_url: https://docs.databricks.com/gcp/en/machine-learning/model-serving/route-optimization
---

# Route optimization on serving endpoints

This article describes how to enable route optimization on your [model serving](https://docs.databricks.com/gcp/en/machine-learning/model-serving/index.md) endpoints. Route optimized serving endpoints dramatically lower overhead latency and allow for substantial improvements in the throughput supported by your endpoint.

Route-optimized endpoints are queried differently from non-route-optimized endpoints, including using a different URL and authentication using OAuth tokens. See [Query route-optimized serving endpoints](https://docs.databricks.com/gcp/en/machine-learning/model-serving/query-route-optimization.md) for details.

## What is route optimization?

When you enable route optimization on an endpoint, Databricks Model Serving improves the network path for inference requests, resulting in faster, more direct communication between your client and the model. This optimized routing unlocks higher queries per second (QPS) compared to non-optimized endpoints and provides more stable and lower latencies for your applications.

> [!TIP]
>
> Route optimization is one of several strategies for optimizing production workloads. For a comprehensive guide to optimization techniques, see [Optimize Model Serving endpoints for production](https://docs.databricks.com/gcp/en/machine-learning/model-serving/production-optimization.md).

## Requirements

* Route optimization on **model serving endpoints** have the same requirements as [non-route-optimized model serving endpoints](https://docs.databricks.com/gcp/en/machine-learning/model-serving/create-manage-serving-endpoints.md#requirement).

## Enable route optimization on a model serving endpoint

### Serving UI

You can enable route optimization when you create a model serving endpoint using the **Serving** UI. You can only enable route optimization during endpoint creation, you can not update existing endpoints to be route optimized.

1. In the sidebar, click **Serving** to display the Serving UI.
2. Click **Create serving endpoint**.
3. In the **Route optimization** section, select **Enable route optimization.**
4. After your endpoint is created, Databricks sends you a notification about what is needed to query a route optimized endpoint.

![Create a model serving endpoint](https://docs.databricks.com/gcp/en/images/machine-learning/create-endpoint.png)

### REST API

To configure your serving endpoint for route optimization using the REST API, specify the `route_optimized` parameter during model serving endpoint creation. You can only specify this parameter during endpoint creation, you can not update existing endpoints to be route optimized.

```bash
POST /api/2.0/serving-endpoints

{
  "name": "my-endpoint",
  "config":
  {
    "served_entities":
    [{
      "entity_name": "ads1",
      "entity_version": "1",
      "workload_type": "CPU",
      "workload_size": "Small",
      "scale_to_zero_enabled": true,
    }],
  },
  "route_optimized": true
}
```

### Python

If you use Python, you can use the following notebook to create a route optimized serving endpoint.

#### Create a route optimized serving endpoint using Python notebook

[Get notebook](https://docs.databricks.com/notebooks/source/machine-learning/create-route-optimized-serving-endpoint.html)

### Databricks SDK

To configure your serving endpoint for route optimization using the Databricks SDK, specify the `route_optimized` parameter during model serving endpoint creation. You can only specify this parameter during endpoint creation, you can not update existing endpoints to be route optimized.

```python
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import EndpointCoreConfigInput, ServedEntityInput

workspace = WorkspaceClient()

workspace.serving_endpoints.create(
  name="my-serving-endpoint",
  config = EndpointCoreConfigInput(
    served_entities=[
    ServedEntityInput(
        entity_name="main.default.my-served-entity",
        scale_to_zero_enabled=True,
        workload_size="Small"
      )
    ]
  ),
  route_optimized=True
)
```

## Limitations

* Route optimization is only available for custom model serving endpoints. Serving endpoints that use [Foundation Model APIs](https://docs.databricks.com/gcp/en/machine-learning/foundation-model-apis/index.md) or [external models](https://docs.databricks.com/gcp/en/machine-learning/foundation-models/external-models/index.md) are not supported.
* Databricks in-house OAuth tokens are the only supported authentication for route optimization. Personal access tokens are not supported.

## Additional resources

* [Query route-optimized serving endpoints](https://docs.databricks.com/gcp/en/machine-learning/model-serving/query-route-optimization.md)
* [Optimize Model Serving endpoints for production](https://docs.databricks.com/gcp/en/machine-learning/model-serving/production-optimization.md)
