跳转到主要内容

快速开始

本页针对的是现代的 google-genai Python SDK(pip install google-genai), 而非已废弃的 google-generativeai 包。
Python
from google import genai

client = genai.Client(
    api_key="sk-orca-...",
    http_options={"base_url": "https://api.orcarouter.ai"},
)

response = client.models.generate_content(
    model="google/gemini-2.5-flash",
    contents="Hello",
)
print(response.text)
SDK 会以 Gemini 标准 JSON 形态请求 https://api.orcarouter.ai/v1beta/models/{model}:generateContent —— OrcaRouter 的一等公民 Gemini 接口表面。流式、函数调用、内联多模态 数据(图片、音频)都可直接使用;尺寸限制和各模型约束请查阅 Google 官方 Gemini API 文档。 SDK 通过 x-goog-api-key 头(或 ?key=... 查询参数)发送 api_key —— OrcaRouter 的鉴权中间件在 /v1beta/... 路径上都识别这两种形式。 完整鉴权头清单见 获取 API 密钥

另见