---
type: concept
x-llmwiki:
  schemaVersion: "0.1"
  contentHash: 727dc05c10958b8f53c052049f421fedce2075b1d01b5e8831979a268ba04774
  pageDirectory: concepts
  sources:
    - query-an-embedding-model-databricks-on-aws.md
  confidence: 0.88
  provenanceState: extracted
  freshnessStatus: unverified
  aliases:
    - databricks-openai-client-for-embeddings
    - DOCFE
    - Databricks OpenAI client
  citations:
    - file: query-an-embedding-model-databricks-on-aws.md
title: Databricks OpenAI Client for Embeddings
description: A Databricks-specific OpenAI-compatible client library (databricks_openai) used to send embedding requests to Databricks-hosted models using the OpenAI embeddings API format.
tags:
  - openai
  - client-library
  - databricks
  - embedding-models
timestamp: "2026-06-19T20:02:09.482Z"
---

# Databricks OpenAI Client for Embeddings

**Databricks OpenAI Client for Embeddings** refers to the use of the `databricks_openai` Python client library — an OpenAI-compatible client — to send embedding requests to foundation models hosted on [Databricks Model Serving](/concepts/databricks-model-serving.md) endpoints. This client provides a familiar interface for users already experienced with OpenAI's API, allowing them to query embedding models served via [Foundation Models APIs](/concepts/foundation-model-apis.md) or [External Models](/concepts/external-models.md). ^[query-an-embedding-model-databricks-on-aws.md]

## Overview

The Databricks OpenAI client (`databricks_openai`) implements the same API interface as the standard OpenAI Python client. Users can call the `client.embeddings.create()` method, specifying the model serving endpoint name as the `model` parameter. The client handles authentication and routing to the Databricks serving endpoint automatically. ^[query-an-embedding-model-databricks-on-aws.md]

## Usage

### Databricks-Hosted Foundation Models

To query a Databricks-hosted embedding model (a foundation model served via Foundation Models APIs), use the `DatabricksOpenAI` client: ^[query-an-embedding-model-databricks-on-aws.md]

```python
from databricks_openai import DatabricksOpenAI

client = DatabricksOpenAI()
response = client.embeddings.create(
    model="databricks-gte-large-en",
    input="what is databricks"
)
```

The `model` parameter specifies the name of the serving endpoint (e.g., `databricks-gte-large-en`). The client automatically authenticates using the workspace's credentials. ^[query-an-embedding-model-databricks-on-aws.md]

### External Models Hosted Outside Databricks

To query a foundation model hosted outside of Databricks (e.g., through [External Models](/concepts/external-models.md)), use the standard OpenAI client directly. You must provide a Databricks API token and the workspace instance URL as the `base_url`: ^[query-an-embedding-model-databricks-on-aws.md]

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key="dapi-your-databricks-token",
    base_url="https://example.staging.cloud.databricks.com/serving-endpoints"
)
response = client.embeddings.create(
    model="databricks-gte-large-en",
    input="what is databricks"
)
```

## Request Format

The underlying REST API request format for embedding models expects an `input` field containing the text to embed: ^[query-an-embedding-model-databricks-on-aws.md]

```json
{
  "input": ["embedding text"]
}
```

For [External Models](/concepts/external-models.md), you can include additional parameters that are valid for a given provider and endpoint configuration. See the documentation on additional query parameters for details. ^[query-an-embedding-model-databricks-on-aws.md]

## Response Format

The response follows the OpenAI embedding response format: ^[query-an-embedding-model-databricks-on-aws.md]

```json
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": []
    }
  ],
  "model": "text-embedding-ada-002-v2",
  "usage": {
    "prompt_tokens": 2,
    "total_tokens": 2
  }
}
```

## Checking Embedding Normalization

To verify whether the embeddings generated by a model are normalized (unit vectors), use the following utility function: ^[query-an-embedding-model-databricks-on-aws.md]

```python
import numpy as np

def is_normalized(vector: list[float], tol=1e-3) -> bool:
    magnitude = np.linalg.norm(vector)
    return abs(magnitude - 1) < tol
```

## Requirements

- See the requirements for querying foundation models.
- Install the appropriate package (`databricks_openai` or `openai`) on your cluster based on the chosen client option. ^[query-an-embedding-model-databricks-on-aws.md]

## Related Concepts

- [Foundation Models APIs](/concepts/foundation-model-apis.md) — Databricks-hosted foundation model serving
- [External Models](/concepts/external-models.md) — Foundation models hosted outside Databricks
- [Model Serving Endpoints](/concepts/model-serving-endpoint.md) — The serving infrastructure that hosts models
- Query a chat model — Companion guide for chat model queries
- Query reasoning models — Companion guide for reasoning model queries
- Query vision models — Companion guide for vision model queries
- [OpenAI client compatibility](/concepts/openai-client-compatibility.md) — The broader pattern of OpenAI-compatible clients on Databricks

## Sources

- query-an-embedding-model-databricks-on-aws.md

# Citations

1. [query-an-embedding-model-databricks-on-aws.md](/references/query-an-embedding-model-databricks-on-aws-18956bab.md)
