---
title: Migrate to Unity Gateway
description: Migrate legacy AI Gateway and model serving workloads to Unity Gateway, and route all AI traffic through Unity Catalog.
canonical_url: https://docs.databricks.com/aws/en/ai-gateway/migrate-to-unity-gateway
---

# Migrate to Unity Gateway

Unity Gateway is the Databricks control plane for enterprise AI. Built on Unity Catalog, it governs model services, external model providers, MCP servers, agents, skills, and tools from one place, with the same privileges, cost controls, guardrails, and observability you use for data. Legacy AI Gateway endpoints stay bound to a single workspace and don't provide this centralized governance.

Use this guide to move existing model serving and legacy AI Gateway workloads to Unity Gateway, and to turn on the **Enforce Unity Gateway** workspace setting so all generative AI traffic is governed through Unity Catalog.

## Requirements

* A Databricks workspace enabled for Unity Catalog. See [Enable a workspace for Unity Catalog](https://docs.databricks.com/aws/en/data-governance/unity-catalog/enable-workspaces.md).
* Workspace admin access to turn on the **Enforce Unity Gateway** setting.
* Account admin access to query the `system.serving` usage tables when you identify legacy traffic.

## Choose your migration path

Pick the path that matches your situation.

| Your situation                                                                                                                                                              | Recommended path                                                                                                                                                                                                                                                                         |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| You don't use AI Gateway, use it only casually, or you're setting up a new account or workspace                                                                             | [Start fresh with Unity Gateway](https://docs.databricks.com/aws/en/ai-gateway/migrate-to-unity-gateway.md#start-fresh-with-unity-gateway).                                                                                                                                              |
| You have active legacy AI Gateway workloads                                                                                                                                 | [Migrate existing workloads](https://docs.databricks.com/aws/en/ai-gateway/migrate-to-unity-gateway.md#migrate-existing-workloads).                                                                                                                                                      |
| You enrolled in the [Foundation Model Unity Catalog Permissions preview](https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/model-uc-permissions.md) | [Migrate existing workloads](https://docs.databricks.com/aws/en/ai-gateway/migrate-to-unity-gateway.md#migrate-existing-workloads), and review your model service permissions. Permissions set on individual models don't automatically grant access to the corresponding model service. |

## <a id="start-fresh-with-unity-gateway" />Start fresh with Unity Gateway

If you're new to Unity Gateway or setting up a new account or workspace, start directly on Unity Gateway.

### Step 1: Review access to Databricks-hosted model services

Unity Gateway provides ready-to-use Databricks-hosted model services in the `system.ai` schema. Review who can access them and restrict access where you need to.

By default, all account users have `EXECUTE` on system-provided model services. Every model service also requires `USE CATALOG` on `system` and `USE SCHEMA` on `system.ai`. To apply least privilege, remove broad schema access and grant `EXECUTE` on individual model services. Underlying model permissions don't grant model service access.

| Action                            | Required permissions                                                                                                          |
| --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| Query a model service             | `EXECUTE` on the model service, plus `USE CATALOG` and `USE SCHEMA` on its catalog and schema.                                |
| Create a model service            | `EXECUTE` on the underlying model, plus `CREATE SERVICE`, `USE CATALOG`, and `USE SCHEMA` where you create the model service. |
| Query an external model provider  | `EXECUTE` on the external model provider, plus `USE CATALOG` and `USE SCHEMA` on its catalog and schema.                      |
| Create an external model provider | `CREATE SERVICE`, `USE CATALOG`, and `USE SCHEMA` where you create the external model provider.                               |

For governed-tag and attribute-based access, see [GRANT policies](https://docs.databricks.com/aws/en/data-governance/unity-catalog/abac/grant-policies.md).

> [!NOTE]
>
> If you were enrolled in the [Foundation Model Unity Catalog Permissions preview](https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/model-uc-permissions.md), permissions set on individual models don't automatically apply to the corresponding model services. Review and reapply your least-privilege grants on the model services.

### <a id="enable-enforce-unity-gateway" />Step 2: Enable Enforce Unity Gateway

Turn on the **Enforce Unity Gateway** workspace setting to disable legacy AI Gateway experiences so all generative AI traffic is governed through Unity Catalog. If you don't turn it on, your existing legacy configurations are unchanged.

When you enable enforcement, each product surface behaves as follows:

| Surface                                                                                                                                                               | Behavior when enforcement is on                                                                                                                                                                                               |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Pay-per-token Foundation Models](https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/index.md)                                                 | All pay-per-token traffic must route through a [model service](https://docs.databricks.com/aws/en/ai-gateway/model-services.md). Databricks-provided pay-per-token serving endpoints (the `databricks-` models) are disabled. |
| [Provisioned Throughput Foundation Models](https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/deploy-prov-throughput-foundation-model-apis.md) | You can no longer create provisioned throughput serving endpoints without Unity Gateway. Existing endpoints stay intact and remain queryable.                                                                                 |
| [External Models](https://docs.databricks.com/aws/en/machine-learning/foundation-models/external-models/index.md)                                                     | You can no longer create external model serving endpoints without Unity Gateway. Existing endpoints stay intact and remain queryable.                                                                                         |

To enable the setting:

1. Log in to your Databricks workspace as a workspace admin.
2. Go to **Settings** > **Advanced**.
3. Turn on **Enforce Unity Gateway**.

After enforcement is on, requests to disabled pay-per-token serving endpoints return a `PERMISSION_DENIED` error:

```json
{
  "error_code": "PERMISSION_DENIED",
  "message": "Querying pay-per-token foundation model endpoint 'databricks-gpt-5' is disabled for this workspace. Please use Unity Gateway."
}
```

> [!WARNING]
>
> Enabling enforcement stops traffic to active legacy endpoints. If your workspace runs legacy workloads, complete [Migrate existing workloads](https://docs.databricks.com/aws/en/ai-gateway/migrate-to-unity-gateway.md#migrate-existing-workloads) and validate that traffic has moved before you turn on the setting.

The **Enforce Unity Gateway** setting is available in workspaces that have legacy AI Gateway endpoints. It stays available after their traffic drops to zero, so you can turn it on at the end of your migration. If the setting isn't available in your workspace, contact your Databricks account team after you complete and validate your migration.

When enforcement is on, the following limitations apply because not all products that relied on legacy serving endpoints have migrated to Unity Gateway:

* **AI Search:** Creating AI Search endpoints through Unity Gateway is not yet supported. Knowledge Assistant and Multi-Agent Supervisor agents that depend on AI Search endpoints don't work.
* **`ai_query`:** `ai_query` supports system-provided model services in `system.ai` only, not custom model services.
* **Custom agents on model serving endpoints:** Custom agents deployed to model serving endpoints can't use [automatic authentication passthrough](https://docs.databricks.com/aws/en/agents/custom-agents/model-serving/agent-authentication-model-serving.md) to query model services. Deploy these agents to Databricks Apps instead. See [Deploy agents](https://docs.databricks.com/aws/en/agents/deploy/index.md).

## <a id="migrate-existing-workloads" />Migrate existing workloads

If you have active legacy AI Gateway workloads, follow these steps before you enable enforcement.

### Step 1: Identify active legacy usage

Find which legacy endpoints still receive traffic, in which workspaces, and who calls them.

1. Enable [usage tracking on your legacy endpoints](https://docs.databricks.com/aws/en/ai-gateway/configure-ai-gateway-endpoints.md). Enabling it is idempotent, so it's safe to re-run.
2. Query the `system.serving.endpoint_usage` and `system.serving.served_entities` system tables for recent requests, callers, and last-request times. Only account admins can query these tables.

### Step 2: Configure model services and providers

Governance configured on a legacy endpoint doesn't carry over. The existing configuration stays on the legacy endpoint. Create or identify the model service or external model provider you need, then re-create the settings you rely on, such as [permissions](https://docs.databricks.com/aws/en/ai-gateway/govern-model-services.md), [rate limits](https://docs.databricks.com/aws/en/ai-gateway/rate-limits.md), [budgets](https://docs.databricks.com/aws/en/ai-gateway/budgets.md), [service policies](https://docs.databricks.com/aws/en/data-governance/unity-catalog/service-policies/index.md), [usage tracking](https://docs.databricks.com/aws/en/ai-gateway/usage-tracking.md), [inference tables](https://docs.databricks.com/aws/en/ai-gateway/inference-tables.md), and [traffic routing and fallbacks](https://docs.databricks.com/aws/en/ai-gateway/configure-traffic-splitting.md). Also update any CI/CD or infrastructure-as-code workflows to use Unity Gateway APIs.

Migrate each workload type to the following target:

| Existing workload                        | Migration target                                                                                                                                                                                                                                                                                                                                                                              |
| ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Databricks-hosted pay-per-token model    | Use the corresponding [system-provided model service](https://docs.databricks.com/aws/en/machine-learning/model-serving/foundation-model-overview.md#system-provided-model-services) in `system.ai`, review its permissions, and re-create the settings you need. See [Discover and govern access to model services](https://docs.databricks.com/aws/en/ai-gateway/govern-model-services.md). |
| Databricks-hosted provisioned throughput | Keep the existing provisioned throughput serving endpoint and create a [model service](https://docs.databricks.com/aws/en/ai-gateway/model-services.md#create-a-model-service) that references it. Grant callers `EXECUTE` on the model service.                                                                                                                                              |
| External provider                        | Create an [external model provider](https://docs.databricks.com/aws/en/ai-gateway/create-model-provider-services.md) with your existing provider, credentials, exposed models, and callers. Query it directly, or create a model service for model-specific governance, in which case the model service's settings take precedence.                                                           |

### Step 3: Update your clients

After you configure the model service or external model provider, move each workload to Unity Gateway. Migrate the gateway URL and the personal access token (PAT) scope together.

**API and SDK clients**: For Databricks-hosted models, change the base URL from `/serving-endpoints` to `/ai-gateway/mlflow/v1` and change the model from the endpoint name to the fully qualified model service name.

```python
from openai import OpenAI

client = OpenAI(
    api_key=token,
    base_url="https://<workspace-url>/ai-gateway/mlflow/v1",
)

response = client.chat.completions.create(
    model="<catalog>.<schema>.<model-service>",
    messages=[...],
)
```

For external models, query the model provider service by passing its name in a request header.

```python
from openai import OpenAI

client = OpenAI(
    api_key=token,
    base_url="https://<workspace-url>/ai-gateway/openai/v1",
    default_headers={
        "Databricks-Model-Provider-Service": "<catalog>.<schema>.<model-provider-service>"
    },
)

response = client.chat.completions.create(
    model="<provider-model-name>",
    messages=[...],
)
```

For more query options, see [Query model services](https://docs.databricks.com/aws/en/ai-gateway/query-model-services.md) and [Query external model providers (model provider services)](https://docs.databricks.com/aws/en/ai-gateway/query-model-provider-services.md).

**Authentication**: Unity Gateway supports both OAuth and PAT authentication. The PAT scope you need depends on the URL:

* **Workspace `/ai-gateway/` route**: Use the recommended, least-privilege `ai-gateway` scope.
* **Legacy regional `*.ai-gateway.*` host**: Use the broader `all-apis` scope.

Calling the legacy regional URL with an `ai-gateway`-scoped PAT returns `403: required scopes: all-apis`. Move the client to the workspace `/ai-gateway/` URL, use an `ai-gateway`-scoped PAT, and retry.

**`ai_query`**: Replace the legacy endpoint name with the corresponding Databricks-provided model service in `system.ai`. The caller needs `EXECUTE` on that model service.

```sql
-- Legacy
SELECT ai_query('<legacy-endpoint-name>', 'Summarize: ' || text)
FROM my_table;
```

```sql
-- Unity Gateway
SELECT ai_query('system.ai.<model-name>', 'Summarize: ' || text)
FROM my_table;
```

`ai_query` supports system-provided model services, not custom model services. Only usage tracking applies. Service policies, inference tables, rate limits, and fallbacks don't apply to `ai_query` calls. See [`ai_query` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/ai_query.md).

**Coding agents**: Configure a supported coding agent to route through Unity Gateway instead of connecting directly to the model provider. Databricks provides the Unity Gateway CLI (`ug`) for this setup. Installing it requires Python 3.12 or later and [`uv`](https://docs.astral.sh/uv/getting-started/installation/).

```bash
uv tool install git+https://github.com/databricks/unity-gateway
```

Launch a supported coding agent through Unity Gateway:

```bash
ug claude
ug codex
ug gemini
ug opencode
ug copilot
```

If you use your own provider credentials, first create an external model provider, then point the coding agent at it. The `--provider` option is supported for `ug claude`, `ug codex`, `ug gemini`, and `ug copilot`.

```bash
ug claude --provider <catalog>.<schema>.<provider-service>
```

See [Get started with coding agents](https://docs.databricks.com/aws/en/ai-gateway/coding-agent-quickstart.md) and [Set up model capacity](https://docs.databricks.com/aws/en/ai-gateway/coding-agent-bring-your-own-providers.md).

### Step 4: Validate migrated traffic

Confirm that legacy traffic has stopped before you enable enforcement. Query the `system.serving.endpoint_usage` table for each legacy endpoint and check that its request count has dropped to zero and its last-request time is before your migration.

### Step 5: (Optional) Throttle legacy endpoints during a phased migration

To migrate gradually, set an individual legacy endpoint's [rate limit](https://docs.databricks.com/aws/en/ai-gateway/rate-limits.md) to `0` to stop new traffic to it while leaving other legacy endpoints active. Repeat steps 2 through 5 for each remaining workload.

### Step 6: Enable Enforce Unity Gateway

After all required traffic has migrated successfully, turn on the **Enforce Unity Gateway** setting to disable legacy endpoints for the workspace. See [Step 2: Enable Enforce Unity Gateway](https://docs.databricks.com/aws/en/ai-gateway/migrate-to-unity-gateway.md#enable-enforce-unity-gateway) for what changes, how to enable the setting, and its limitations.

## Additional resources

* [AI governance with Unity Gateway](https://docs.databricks.com/aws/en/ai-gateway/index.md)
* [AI governance guide](https://docs.databricks.com/aws/en/ai-gateway/ai-governance.md)
* [Create and manage custom model services](https://docs.databricks.com/aws/en/ai-gateway/model-services.md#create-a-model-service)
* [Govern external model providers (model provider services)](https://docs.databricks.com/aws/en/ai-gateway/model-provider-services.md)
* [Unity Gateway release notes](https://docs.databricks.com/aws/en/release-notes/unity-gateway/index.md)
