Source: https://ailoot.ai/docs/zh-hant-tw/integrations/google-genai-python/
Canonical: https://ailoot.ai/docs/zh-hant-tw/integrations/google-genai-python/
Language: zh-hant-tw

[SDK與框架](https://ailoot.ai/docs/zh-hant-tw/integrations/#sdk) 

# Google GenAI SDK (Python)

[Markdown](https://ailoot.ai/docs/zh-hant-tw/integrations/google-genai-python/index.md)

SDK · Gemini

| 格式 | 設定位置 |
| --- | --- |
| Gemini | genai.Client(api\_key=..., http\_options=types.HttpOptions(base\_url=...)) |

## [](https://ailoot.ai/docs/zh-hant-tw/integrations/google-genai-python/#setup)設定

複製設定，並將`sk-...`替換為您的 Ailoot 控制台金鑰。若應用程式支援，最好將金鑰存放在環境變數`AILOOT_API_KEY`中。

執行前，請使用 Ailoot 金鑰呼叫 GET /v1/models。選擇支援方法包含 POST /v1beta/models/{model}:generateContent 的確切模型 ID，並填入設定。使用代理程式時，也請確認工具支援及客戶端版本所需的功能。

```python
import os
from google import genai
from google.genai import types
client = genai.Client(
    api_key=os.environ["AILOOT_API_KEY"],
    http_options=types.HttpOptions(base_url="https://api.ailoot.ai"))
r = client.models.generate_content(model="gemini-3.6-flash", contents="你好")
print(r.text)
```

模型範例：`gemini-3.6-flash, gemini-3.1-pro`。若要使用其他模型，請從此處選取：[目錄](https://ailoot.ai/models/zh-hant-tw/) —請確認模型支援所需格式。

## [](https://ailoot.ai/docs/zh-hant-tw/integrations/google-genai-python/#notes)重要須知

位址不含 /v1beta，SDK 會自行組合 /v1beta/models/{model}:generateContent。金鑰透過 x-goog-api-key 標頭傳送，Ailoot 接受此方式。僅可使用 Gemini 格式的模型。JavaScript 版本 (@google/genai) 的說明文件未描述自訂位址，因此此處不提供該版本的範例。

## [](https://ailoot.ai/docs/zh-hant-tw/integrations/google-genai-python/#check)驗證

- Gemini 格式的位址為`https://api.ailoot.ai`不含`/v1beta`。
- 提出一個簡短問題。若收到錯誤，請查看代碼與Request ID，並對照此頁面：[錯誤與限制](https://ailoot.ai/docs/zh-hant-tw/errors/)。
- `404`: `https://api.ailoot.ai` → `/v1beta/models/{model}:generateContent`. 執行前，請使用 Ailoot 金鑰呼叫 GET /v1/models。選擇支援方法包含 POST /v1beta/models/{model}:generateContent 的確切模型 ID，並填入設定。使用代理程式時，也請確認工具支援及客戶端版本所需的功能。
- 402 表示餘額不足以涵蓋保留金額。代理需要保留的金額比聊天更多：[原因](https://ailoot.ai/docs/zh-hant-tw/billing/reserve/)。

應用程式說明文件：[https://github.com/googleapis/python-genai#custom-base-url](https://github.com/googleapis/python-genai#custom-base-url)

還有疑問嗎？請提供 Request ID與問題描述，我們會協助釐清。[聯絡支援](mailto:support@ailoot.ai)

## Ailoot · 公司及其專案組合





Ailoot以累積的營運經驗、廣大的客戶群、穩定的服務及持續的KPI管理為基礎。





公司及其專案組合：數百萬客戶，每月銷售額達數十億。





Ailoot將這些營運經驗用於API存取，讓客戶的產品、代理、應用程式及自動化流程使用AI功能。
