---
title: Custom model services
description: Create and manage custom model services in Unity Catalog to route inference requests, configure fallbacks, grant access, and monitor usage.
canonical_url: https://docs.databricks.com/aws/en/ai-gateway/model-services
---

# Custom model services

A [model service](https://docs.databricks.com/aws/en/unity-gateway/concepts.md#model-service) is an endpoint that translates and routes inference requests to one or more models, with [traffic splitting and fallbacks](https://docs.databricks.com/aws/en/ai-gateway/configure-traffic-splitting.md). It supports [real-time requests](https://docs.databricks.com/aws/en/ai-gateway/query-model-services.md), plus [batch inference](https://docs.databricks.com/aws/en/ai-gateway/query-model-services.md#ai-query).

You can create a custom model service to represent a "virtual model" for use cases such as:

* **A model-agnostic endpoint for an application.** Give a customer-support assistant a service named `production.ai.support-assistant`. Change the underlying model without changing the name the application calls.
* **Custom routing and fallbacks.** Use [traffic splitting](https://docs.databricks.com/aws/en/ai-gateway/configure-traffic-splitting.md) to send 10% of traffic to a new model before a broader rollout, or configure a backup destination for failed requests.
* **A budget for one workload.** Tag a service with `project=support-assistant` and scope a [monthly budget](https://docs.databricks.com/aws/en/ai-gateway/budgets.md) to that tag, with an alert at $1,000 of spend.
* **Access controls for a team.** Grant the legal team and its application service principals [access](https://docs.databricks.com/aws/en/ai-gateway/model-services.md#grant-access-to-a-model-service) to a `legal-review` service, and use separate services for other teams.
* **Rate limits for a workload.** Configure a test service for 100 requests per minute and a production service for 1,000 requests per minute using [service rate limits](https://docs.databricks.com/aws/en/ai-gateway/rate-limits.md).
* **Separate monitoring and logs.** Send a support assistant's requests and responses to a dedicated [inference table](https://docs.databricks.com/aws/en/ai-gateway/inference-tables.md) so its traffic can be inspected separately from coding-agent traffic.

To query a Databricks-served foundation model without creating a service, use a [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`.

A service can route to Databricks-served models, using [pay-per-token](https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/index.md#token-foundation-apis) or [provisioned throughput](https://docs.databricks.com/aws/en/machine-learning/foundation-model-apis/index.md#throughput), or to external models through a [model provider](https://docs.databricks.com/aws/en/unity-gateway/concepts.md#model-provider). You can mix these destinations in one service.

Custom model services are Unity Catalog securables. Callers invoke them by their fully qualified name, `catalog.schema.name`, across workspaces or from outside Databricks. See [Governance and privileges](https://docs.databricks.com/aws/en/ai-gateway/model-services.md#privileges).

## Requirements

> [!NOTE]
>
> Unity Gateway is not supported on AWS GovCloud.

* A Databricks workspace in a [Unity Gateway supported region](https://docs.databricks.com/aws/en/resources/feature-region-support.md#model-serving-features-availability).
* Unity Catalog enabled for your workspace. See [Enable a workspace for Unity Catalog](https://docs.databricks.com/aws/en/data-governance/unity-catalog/enable-workspaces.md).
* To create a model service, you must have:
  * `USE CATALOG`, `USE SCHEMA`, and `CREATE SERVICE` on the catalog and schema where you create the model service.
  * `EXECUTE` on each model that the model service references as a destination.
  * `EXECUTE`, `USE CATALOG`, and `USE SCHEMA` on each [model provider](https://docs.databricks.com/aws/en/unity-gateway/concepts.md#model-provider) that the model service references as a destination.
  * `USE CATALOG`, `USE SCHEMA`, and `CREATE TABLE` on the catalog and schema where the inference table is created, if you enable inference logging.

## Create a custom model service <a id="create-a-model-service" />

Create a model service in the Unity Gateway UI or Catalog Explorer. To create one programmatically, use the REST API, the Databricks SDKs, the Databricks CLI, Terraform, or Declarative Automation Bundles (DABs).

Model services and [model providers](https://docs.databricks.com/aws/en/unity-gateway/concepts.md#model-provider) share a single namespace within a Unity Catalog schema. You can't use a name for a model service if a model provider in the schema already uses it, and vice versa.

### UI

1. Do one of the following:
   * In the workspace sidebar, click **AI Gateway**, then click **+ Model**.
   * In Catalog Explorer, go to the schema where you want to create the model service, then click **Create** > **Service** > **Model service**.
2. Enter a name for the model service, and select the catalog and schema to create it in. If you start from Catalog Explorer, Catalog Explorer prefills the catalog and schema.
3. Select the primary destination to serve. This destination can be a Databricks-served model that you have `EXECUTE` on and that Unity Gateway can serve, or a [model provider](https://docs.databricks.com/aws/en/unity-gateway/concepts.md#model-provider) that you have `EXECUTE`, `USE CATALOG`, and `USE SCHEMA` on.
4. Click **Create**.

After you create the model service, Databricks opens its overview page, where you can get started or configure additional features such as inference logging.

### REST API

Send a `POST` to [/api/2.1/unity-catalog/model-services](https://docs.databricks.com/api/ai-gateway/v1/create-model-service), passing `parent` and `model_service_id` as query parameters. The routing config must have at least one destination:

```bash
databricks api post \
  "/api/2.1/unity-catalog/model-services?parent=schemas/main.default&model_service_id=my_model_service" \
  --json '{
  "comment": "Routes chat traffic to a foundation model",
  "config": {
    "routing": {
      "destinations": [
        {
          "name": "primary",
          "destination_type": "DESTINATION_TYPE_PAY_PER_TOKEN_FOUNDATION_MODEL",
          "pay_per_token_config": { "model": "models/system.ai.databricks-gpt-5" },
          "traffic_percentage": 100
        }
      ]
    }
  }
}'
```

### CLI

Pass the parent schema and a leaf name, and supply the config with `--json`. The routing config must have at least one destination. To install the CLI, see [Install or update the Databricks CLI](https://docs.databricks.com/aws/en/dev-tools/cli/install.md).

```bash
databricks ai-gateway create-model-service schemas/main.default my_model_service --json '{
  "comment": "Routes chat traffic to a foundation model",
  "config": {
    "routing": {
      "destinations": [
        {
          "name": "primary",
          "destination_type": "DESTINATION_TYPE_PAY_PER_TOKEN_FOUNDATION_MODEL",
          "pay_per_token_config": { "model": "models/system.ai.databricks-gpt-5" },
          "traffic_percentage": 100
        }
      ]
    }
  }
}'
```

### Terraform

Create and manage a model service with the [Databricks Terraform provider](https://docs.databricks.com/aws/en/dev-tools/terraform/index.md) and the [databricks\_ai\_gateway\_model\_service](https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/ai_gateway_model_service) resource:

```hcl
resource "databricks_ai_gateway_model_service" "example" {
  parent           = "schemas/main.default"
  model_service_id = "my_model_service"
  comment          = "Routes chat traffic to a foundation model"

  config = {
    routing = {
      destinations = [{
        name                 = "primary"
        destination_type     = "DESTINATION_TYPE_PAY_PER_TOKEN_FOUNDATION_MODEL"
        pay_per_token_config = { model = "models/system.ai.databricks-gpt-5" }
        traffic_percentage   = 100
      }]
    }
  }
}
```

### DABs (Beta)

Define the model service in a [bundle](https://docs.databricks.com/aws/en/dev-tools/bundles/index.md) and deploy it with `databricks bundle deploy`. The routing config must have at least one destination:

```yaml
resources:
  model_services:
    my_model_service:
      parent: schemas/main.default
      model_service_id: my_model_service
      comment: Routes chat traffic to a foundation model
      config:
        routing:
          destinations:
            - name: primary
              destination_type: DESTINATION_TYPE_PAY_PER_TOKEN_FOUNDATION_MODEL
              pay_per_token_config:
                model: models/system.ai.databricks-gpt-5
              traffic_percentage: 100
```

### Python SDK

Create and manage a model service with the [Databricks SDK for Python](https://docs.databricks.com/aws/en/dev-tools/sdk-python.md):

```python
from databricks.sdk.service import catalog as c

model_service = w.ai_gateway.create_model_service(
    parent="schemas/main.default",
    model_service_id="my_model_service",
    model_service=c.ModelService(
        comment="Routes chat traffic to a foundation model",
        config=c.ModelServiceConfig(
            routing=c.ModelServiceConfigRoutingConfig(
                destinations=[
                    c.ModelServiceConfigDestinationConfig(
                        name="primary",
                        destination_type=(
                            c.ModelServiceConfigDestinationConfigDestinationType
                            .DESTINATION_TYPE_PAY_PER_TOKEN_FOUNDATION_MODEL
                        ),
                        pay_per_token_config=c.ModelServiceConfigPayPerTokenConfig(
                            model="models/system.ai.databricks-gpt-5"
                        ),
                        traffic_percentage=100,
                    )
                ]
            )
        ),
    ),
)
```

### Go SDK

Create and manage a model service with the [Databricks SDK for Go](https://docs.databricks.com/aws/en/dev-tools/sdk-go.md):

```go
modelService, err := w.AiGateway.CreateModelService(ctx, catalog.CreateModelServiceRequest{
	Parent:         "schemas/main.default",
	ModelServiceId: "my_model_service",
	ModelService: catalog.ModelService{
		Comment: "Routes chat traffic to a foundation model",
		Config: &catalog.ModelServiceConfig{
			Routing: &catalog.ModelServiceConfigRoutingConfig{
				Destinations: []catalog.ModelServiceConfigDestinationConfig{{
					Name:            "primary",
					DestinationType: catalog.ModelServiceConfigDestinationConfigDestinationTypeDestinationTypePayPerTokenFoundationModel,
					PayPerTokenConfig: &catalog.ModelServiceConfigPayPerTokenConfig{
						Model: "models/system.ai.databricks-gpt-5",
					},
					TrafficPercentage: 100,
				}},
			},
		},
	},
})
```

### Go Modular SDK

Create and manage a model service with the [Databricks AI Gateway SDK for Go](https://pkg.go.dev/github.com/databricks/sdk-go/aigateway). Optional fields are pointers, so the example uses a one-line helper, `func ptr[T any](v T) *T { return &v }`.

```go
modelService, err := c.CreateModelService(ctx, aigateway.CreateModelServiceRequest{
	Parent:         ptr("schemas/main.default"),
	ModelServiceId: ptr("my_model_service"),
	ModelService: &aigateway.ModelService{
		Comment: ptr("Routes chat traffic to a foundation model"),
		Config: &aigateway.ModelServiceConfig{
			Routing: &aigateway.ModelServiceConfig_RoutingConfig{
				Destinations: []aigateway.ModelServiceConfig_DestinationConfig{{
					Name:              ptr("primary"),
					DestinationType:   aigateway.ModelServiceConfig_DestinationConfig_DestinationType_DestinationTypePayPerTokenFoundationModel,
					TrafficPercentage: ptr(100),
					TypeConfig: &aigateway.ModelServiceConfig_DestinationConfig_TypeConfig_PayPerTokenConfig{
						PayPerTokenConfig: aigateway.ModelServiceConfig_PayPerTokenConfig{
							Model: ptr("models/system.ai.databricks-gpt-5"),
						},
					},
				}},
			},
		},
	},
})
```

### Java SDK

Create and manage a model service with the [Databricks SDK for Java](https://docs.databricks.com/aws/en/dev-tools/sdk-java.md):

```java
ModelServiceConfig config =
    new ModelServiceConfig()
        .setRouting(
            new ModelServiceConfigRoutingConfig()
                .setDestinations(
                    Collections.singletonList(
                        new ModelServiceConfigDestinationConfig()
                            .setName("primary")
                            .setDestinationType(
                                ModelServiceConfigDestinationConfigDestinationType
                                    .DESTINATION_TYPE_PAY_PER_TOKEN_FOUNDATION_MODEL)
                            .setPayPerTokenConfig(
                                new ModelServiceConfigPayPerTokenConfig()
                                    .setModel("models/system.ai.databricks-gpt-5"))
                            .setTrafficPercentage(100L))));

ModelService modelService =
    w.aiGateway()
        .createModelService(
            new CreateModelServiceRequest()
                .setParent("schemas/main.default")
                .setModelServiceId("my_model_service")
                .setModelService(
                    new ModelService()
                        .setComment("Routes chat traffic to a foundation model")
                        .setConfig(config)));
```

### JS Modular SDK

Create and manage a model service with the [Databricks AI Gateway SDK for JavaScript](https://www.npmjs.com/package/@databricks/sdk-aigateway):

```typescript
import { ModelServiceConfig_DestinationConfig_DestinationType as DestType } from '@databricks/sdk-aigateway/v1';

const created = await client.createModelService({
  parent: 'schemas/main.default',
  modelServiceId: 'my_model_service',
  modelService: {
    comment: 'Routes chat traffic to a foundation model',
    config: {
      routing: {
        destinations: [
          {
            name: 'primary',
            destinationType: DestType.DESTINATION_TYPE_PAY_PER_TOKEN_FOUNDATION_MODEL,
            typeConfig: {
              $case: 'payPerTokenConfig',
              payPerTokenConfig: { model: 'models/system.ai.databricks-gpt-5' },
            },
            trafficPercentage: 100,
          },
        ],
      },
    },
  },
});
```

## Grant access to a model service <a id="grant-access-to-a-model-service" />

By default, only the model service owner can query it. To let others query a model service, grant them `EXECUTE` on it, plus `USE CATALOG` and `USE SCHEMA` on its catalog and schema. If the model service logs to an inference table, grant `SELECT` on the table to let them read the logged requests and responses.

### UI

1. Open the model service in Catalog Explorer, or go to **AI Gateway** and select the service.
2. Go to the **Permissions** tab.
3. Click **Grant**.
4. Select the users, groups, or service principals to give access to.
5. Select the **EXECUTE** privilege.
6. Click **Grant**.

### REST API

```bash
databricks api patch \
  "/api/2.1/unity-catalog/permissions/model_service/main.default.my_model_service" \
  --json '{
    "changes": [
      { "principal": "data-team", "add": ["EXECUTE"] }
    ]
  }'
```

### CLI

Grant `EXECUTE` with the Databricks CLI. To install the CLI, see [Install or update the Databricks CLI](https://docs.databricks.com/aws/en/dev-tools/cli/install.md).

```bash
databricks grants update model_service main.default.my_model_service \
  --json '{"changes": [{"principal": "data-team", "add": ["EXECUTE"]}]}'
```

### Terraform

Grant `EXECUTE` with the [Databricks Terraform provider](https://docs.databricks.com/aws/en/dev-tools/terraform/index.md) and the `databricks_grant` resource:

```hcl
resource "databricks_grant" "example" {
  model_service = "main.default.my_model_service"
  principal     = "data-team"
  privileges    = ["EXECUTE"]
}
```

### DABs (Beta)

Add a `grants` block to the model service resource in your bundle and redeploy to grant access.

```yaml
resources:
  model_services:
    my_model_service:
      parent: schemas/main.default
      model_service_id: my_model_service
      comment: Routes chat traffic to a foundation model
      config:
        routing:
          destinations:
            - name: primary
              destination_type: DESTINATION_TYPE_PAY_PER_TOKEN_FOUNDATION_MODEL
              pay_per_token_config:
                model: models/system.ai.databricks-gpt-5
              traffic_percentage: 100
      grants:
        - principal: data-team
          privileges: [EXECUTE]
```

### Python SDK

Grant `EXECUTE` with the [Databricks SDK for Python](https://docs.databricks.com/aws/en/dev-tools/sdk-python.md):

```python
from databricks.sdk.service import catalog as c

w.grants.update(
    securable_type="model_service",
    full_name="main.default.my_model_service",
    changes=[c.PermissionsChange(principal="data-team", add=[c.Privilege.EXECUTE])],
)
```

### Go SDK

Grant `EXECUTE` with the [Databricks SDK for Go](https://docs.databricks.com/aws/en/dev-tools/sdk-go.md):

```go
_, err := w.Grants.Update(ctx, catalog.UpdatePermissions{
	SecurableType: "model_service",
	FullName:      "main.default.my_model_service",
	Changes: []catalog.PermissionsChange{{
		Principal: "data-team",
		Add:       []catalog.Privilege{catalog.PrivilegeExecute},
	}},
})
```

### Java SDK

Grant `EXECUTE` with the [Databricks SDK for Java](https://docs.databricks.com/aws/en/dev-tools/sdk-java.md):

```java
w.grants().update(
    new UpdatePermissions()
        .setSecurableType("model_service")
        .setFullName("main.default.my_model_service")
        .setChanges(Arrays.asList(
            new PermissionsChange().setPrincipal("data-team").setAdd(Arrays.asList(Privilege.EXECUTE)))));
```

See [Discover and govern access to model services](https://docs.databricks.com/aws/en/ai-gateway/govern-model-services.md) for more about granting and discovering access.

## Configure features on a model service <a id="configure-features-on-a-model-service" />

Configure rate limits, inference logging, and guardrails implemented with [service policies](https://docs.databricks.com/aws/en/data-governance/unity-catalog/service-policies/index.md) on the model service from the Unity Gateway UI. See:

* [Apply rate limits to model and MCP services](https://docs.databricks.com/aws/en/ai-gateway/rate-limits.md)
* [Log requests and responses to inference tables](https://docs.databricks.com/aws/en/ai-gateway/inference-tables.md)

### Inference logging <a id="inference-logging" />

When you enable inference logging, Databricks creates a new, empty Unity Catalog table with a predefined schema at the location you specify. Note the following:

* You must have `USE CATALOG`, `USE SCHEMA`, and `CREATE TABLE` on the target catalog and schema.
* The creator of the model service is the owner of the inference table. No other users have access unless you grant it.
* If a table already exists at the specified location, creating the model service fails.
* The inference table has an independent lifecycle from the model service. If you drop the table, the model service keeps working but stops logging.

For more about inference tables, see [Log requests and responses to inference tables](https://docs.databricks.com/aws/en/ai-gateway/inference-tables.md).

## Update a model service <a id="update-a-model-service" />

You must be an owner or have `MANAGE`.

### UI

Edit the model service's configuration from the Unity Gateway UI or Catalog Explorer. Changes apply in place.

### REST API

```bash
databricks api patch \
  "/api/2.1/unity-catalog/model-services/main.default.my_model_service?update_mask=comment" \
  --json '{"comment": "Updated: routes chat traffic"}'
```

### CLI

```bash
databricks ai-gateway update-model-service model-services/main.default.my_model_service comment \
  --json '{"comment": "Updated: routes chat traffic"}'
```

### Terraform

Edit `comment` (or any other mutable field) on the `databricks_ai_gateway_model_service` resource and re-apply. Changes apply in place.

### DABs (Beta)

Edit `comment` (or any other mutable field) in the bundle resource and run `databricks bundle deploy`. Changes apply in place.

### Python SDK

```python
from databricks.sdk.service import catalog as c
from google.protobuf.field_mask_pb2 import FieldMask

updated = w.ai_gateway.update_model_service(
    name="model-services/main.default.my_model_service",
    update_mask=FieldMask(paths=["comment"]),
    model_service=c.ModelService(comment="Updated: routes chat traffic"),
)
```

### Go SDK

```go
updated, err := w.AiGateway.UpdateModelService(ctx, catalog.UpdateModelServiceRequest{
	Name:         "model-services/main.default.my_model_service",
	UpdateMask:   *fieldmask.New([]string{"comment"}),
	ModelService: catalog.ModelService{Comment: "Updated: routes chat traffic"},
})
```

### Go Modular SDK

```go
mask, err := types.NewFieldMask[aigateway.ModelService]("comment")
updated, err := c.UpdateModelService(ctx, aigateway.UpdateModelServiceRequest{
	ModelService: &aigateway.ModelService{
		Name:    ptr("model-services/main.default.my_model_service"),
		Comment: ptr("Updated: routes chat traffic"),
	},
	UpdateMask: mask,
})
```

### Java SDK

```java
ModelService updated =
    w.aiGateway()
        .updateModelService(
            new UpdateModelServiceRequest()
                .setName("model-services/main.default.my_model_service")
                .setUpdateMask(FieldMask.newBuilder().addPaths("comment").build())
                .setModelService(
                    new ModelService().setComment("Updated: routes chat traffic")));
```

### JS Modular SDK

```typescript
import { modelServiceFieldMask } from '@databricks/sdk-aigateway/v1';

const updated = await client.updateModelService({
  modelService: {
    name: 'model-services/main.default.my_model_service',
    comment: 'Updated: routes chat traffic',
  },
  updateMask: modelServiceFieldMask('comment'),
});
```

## Delete a model service <a id="delete-a-model-service" />

You must be an owner or have `MANAGE`. System-provided model services in `system.ai` cannot be deleted.

### UI

Open the model service in the Unity Gateway UI or Catalog Explorer and select **Delete** from the kebab menu.

### REST API

```bash
databricks api delete "/api/2.1/unity-catalog/model-services/main.default.my_model_service"
```

### CLI

```bash
databricks ai-gateway delete-model-service model-services/main.default.my_model_service
```

### Terraform

Run `terraform destroy`, or remove the resource block and re-apply.

### DABs (Beta)

Remove the resource from the bundle and run `databricks bundle deploy` to delete it. `databricks bundle destroy` also works, but it removes every resource the bundle manages, not just this one.

### Python SDK

```python
w.ai_gateway.delete_model_service(name="model-services/main.default.my_model_service")
```

### Go SDK

```go
err := w.AiGateway.DeleteModelService(ctx, catalog.DeleteModelServiceRequest{
	Name: "model-services/main.default.my_model_service",
})
```

### Go Modular SDK

```go
err := c.DeleteModelService(ctx, aigateway.DeleteModelServiceRequest{
	Name: ptr("model-services/main.default.my_model_service"),
})
```

### Java SDK

```java
w.aiGateway()
    .deleteModelService(
        new DeleteModelServiceRequest().setName("model-services/main.default.my_model_service"));
```

### JS Modular SDK

```typescript
await client.deleteModelService({ name: 'model-services/main.default.my_model_service' });
```

## Governance and privileges <a id="privileges" />

As a Unity Catalog securable object, a model service:

* **Lives in a catalog and schema**, where it inherits schema settings such as workspace bindings.
* **Carries standard Unity Catalog metadata**, such as name, owner, comment, and tags.
* **Is governed by Unity Catalog privileges**, so you grant access using the same `GRANT` and `REVOKE` statements you use for tables, functions, and models.
* **Is discoverable in Catalog Explorer**, alongside the rest of your Unity Catalog assets.

The following privileges apply:

| Privilege                   | Description                                                                                   |
| --------------------------- | --------------------------------------------------------------------------------------------- |
| `USE CATALOG`, `USE SCHEMA` | Access the catalog and schema that contain the model service. Required for all operations.    |
| `CREATE SERVICE`            | Create model services in a schema. Granted on the catalog or schema.                          |
| `EXECUTE`                   | Query a model service.                                                                        |
| `MANAGE`                    | Modify or delete a model service and manage its grants. The owner has a superset of `MANAGE`. |

Model services use definer's privileges. Databricks evaluates a query against the *owner's* privileges rather than the caller's. When a user queries a model service, Databricks checks that the owner has `EXECUTE` on the referenced destinations, such as the underlying models and any [model providers](https://docs.databricks.com/aws/en/ai-gateway/model-provider-services.md). The caller does not need direct access to those destinations.

## Limitations

The following capabilities are not supported:

* Creating and managing model services with SQL.
* Discovering model services with only the `BROWSE` privilege.
* Global search for model services.

## Additional resources <a id="additional-resources" />

* [Query model services](https://docs.databricks.com/aws/en/ai-gateway/query-model-services.md)
* [Discover and govern access to model services](https://docs.databricks.com/aws/en/ai-gateway/govern-model-services.md)
* [Integrate with coding agents](https://docs.databricks.com/aws/en/ai-gateway/coding-agent-quickstart.md)
* [Track model service and provider lineage](https://docs.databricks.com/aws/en/data-governance/unity-catalog/ai-gateway-service-lineage.md)
