Query with the Google Gemini API
important
The Google Gemini API is only compatible with Gemini pay per token foundation models. For a unified API that works across all providers, use the Chat Completions API.
The Google Gemini API provides native Google AI SDK compatibility for Gemini models on Databricks. Use this API when you need Gemini-specific features or are migrating existing Google AI SDK code.
Requirements
- See Requirements.
- Install the
google-genaipackage on your compute.
Query examples
The following examples show how to query a Foundation Model API pay-per-token endpoint using the Google Gemini API.
- Python
- REST API
Python
from google import genai
from google.genai import types
import os
DATABRICKS_TOKEN = os.environ.get('DATABRICKS_TOKEN')
client = genai.Client(
api_key="databricks",
http_options=types.HttpOptions(
base_url="https://example.staging.cloud.databricks.com/serving-endpoints/gemini",
headers={
"Authorization": f"Bearer {DATABRICKS_TOKEN}",
},
),
)
response = client.models.generate_content(
model="databricks-gemini-2-5-pro",
contents=[
types.Content(
role="user",
parts=[types.Part(text="What is a mixture of experts model?")],
),
],
config=types.GenerateContentConfig(
max_output_tokens=256,
),
)
print(response.text)
Bash
curl \
-u token:$DATABRICKS_TOKEN \
-X POST \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [{"text": "What is a mixture of experts model?"}]
}
],
"generationConfig": {
"maxOutputTokens": 256
}
}' \
https://<workspace_host>.databricks.com/serving-endpoints/gemini/v1beta/models/databricks-gemini-2-5-pro:generateContent
Supported models
Databricks-hosted foundation models
databricks-gemini-3-prodatabricks-gemini-3-flashdatabricks-gemini-2-5-prodatabricks-gemini-2-5-flash