メインコンテンツまでスキップ

Google Gemini API によるクエリ

重要

Google Gemini API 、Gemini 政府単位の従量課金基盤モデルとのみ互換性があります。 すべてのプロバイダーで機能する統合 API については、 Chat Completions API を使用してください。

Google Gemini API は、Databricks 上の Gemini モデルにネイティブの Google AI SDK 互換性を提供します。Gemini 固有の機能が必要な場合、または既存の Google AI SDK コードを移行する場合は、この API を使用します。

要件

  • 要件を参照してください。
  • google-genaiパッケージをコンピュートにインストールします。

クエリの例

次の例は、Google Gemini APIを使用して基盤モデル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)

サポートされているモデル

Databricks がホストする基盤モデル

  • databricks-gemini-3-pro
  • databricks-gemini-3-flash
  • databricks-gemini-2-5-pro
  • databricks-gemini-2-5-flash

その他のリソース