Skip to main content

Databricks OpenAI Integration

The databricks-openai package provides seamless integration of Databricks AI features into OpenAI applications.

Installation

From PyPI

pip install databricks-openai

From Source

pip install git+https://git@github.com/databricks/databricks-ai-bridge.git#subdirectory=integrations/openai

Key Features

  • Vector Search: Store and query vector representations using VectorSearchRetrieverTool.
  • Sandbox: Run an OpenAI Agents SDK agent's shell and filesystem tools inside a Databricks sandbox with DatabricksSandboxClient (install databricks-openai[sandbox]).

Getting Started

Use Vector Search on Databricks

# Step 1: call model with VectorSearchRetrieverTool defined
dbvs_tool = VectorSearchRetrieverTool(index_name="catalog.schema.my_index_name")
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {
        "role": "user",
        "content": "Using the Databricks documentation, answer what is Spark?"
    }
]
first_response = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    tools=[dbvs_tool.tool]
)

# Step 2: Execute function code – parse the model's response and handle function calls.
tool_call = first_response.choices[0].message.tool_calls[0]
args = json.loads(tool_call.function.arguments)
result = dbvs_tool.execute(query=args["query"])  # For self-managed embeddings, optionally pass in openai_client=client

# Step 3: Supply model with results – so it can incorporate them into its final response.
messages.append(first_response.choices[0].message)
messages.append({
    "role": "tool",
    "tool_call_id": tool_call.id,
    "content": json.dumps(result)
})
second_response = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    tools=tools
)

Run an agent in a Databricks sandbox

Install the extra:

pip install databricks-openai[sandbox]

Register DatabricksSandboxClient as the sandbox backend on a RunConfig. The client provisions a Databricks sandbox when the run starts and tears it down when it finishes, so the agent's shell and filesystem tools execute inside the sandbox:

from agents.run_config import RunConfig, SandboxRunConfig
from databricks_openai import DatabricksSandboxClient, DatabricksSandboxClientOptions

run_config = RunConfig(
    sandbox=SandboxRunConfig(
        client=DatabricksSandboxClient(profile="DEFAULT"),
        options=DatabricksSandboxClientOptions(),
    )
)

# Pass run_config to your Runner, e.g. Runner.run(agent, input, run_config=run_config)

DatabricksSandboxClient(profile=...) builds a WorkspaceClient from the named Databricks CLI profile; to reuse an existing client, pass DatabricksSandboxClient(client=...) instead.


Contribution Guide

We welcome contributions! Please see our contribution guidelines for details.

Cross-version compatibility tests

The openai_cross_version_test CI job installs current core with an unchanged historical OpenAI integration. It runs the maintained tests in tests/compatibility rather than the historical release's tests, so the test harness uses the tracing API supported by current core. The 24 cases cover retriever construction, resources, retrieval results, and persisted traces. Resource expectations retain the differences between historical releases. External services are mocked; MLflow writes traces to a temporary local store.

To reproduce from the repository root, with a historical checkout at older-version:

pip install . older-version/integrations/openai --group dev
pip check
pytest -c pyproject.toml integrations/openai/tests/compatibility

License

This project is licensed under the MIT License.

Thank you for using Databricks OpenAI!

Metadata

Release files for databricks-openai 0.19.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for databricks-openai 0.19.0
File Size Uploaded Provenance Actions
databricks_openai-0.19.0.tar.gz 29.9 kB Without provenance Details for databricks_openai-0.19.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for databricks-openai 0.19.0
File Interpreter ABI Platform Actions
databricks_openai-0.19.0-py3-none-any.whl Python 3 none any Details for databricks_openai-0.19.0-py3-none-any.whl

Total release size: 63.7 kB

Release files / databricks_openai-0.19.0.tar.gz

Download URL databricks_openai-0.19.0.tar.gz
Size 29.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d4d2b050b577495b47b9c7bad1b4642afc3458c0198d6035f76b2757dc4365e4
BLAKE2b-256 checksum
How to use checksums
7e424d7cc03b30c14dc5e05fc53e5e03736a4b8ea01094127705eb2101472267
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / databricks_openai-0.19.0-py3-none-any.whl

Download URL databricks_openai-0.19.0-py3-none-any.whl
Size 33.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43bf6b85c140819db1bef5a5bad288e16f14225641cffbf80290b1ab4cf17768
BLAKE2b-256 checksum
How to use checksums
4cd9eb777053eb0abe092a9a4da0147d54ccf3787a777e6345dd8d855eaded2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.3

Security for databricks-openai 0.19.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page