Endpoint: POST /projects/cognition/locations/us/publishers/google/models/{model}:generateContent
通过 Google 的 Gemini 模型生成文本或多模态内容。
import requests
url = "https://api.yourouter.ai/v1/projects/cognition/locations/us/publishers/google/models/gemini-1.5-pro-latest:generateContent"
response = requests.post(
url,
headers={
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
"vendor": "google"
},
json={
"contents": [
{"role": "user", "parts": [{"text": "hello gemini"}]}
]
}
)
print(response.json())
要使用的 Gemini 模型,例如 gemini-1.5-pro-latest。
图片输入
对于图片内容,请使用 inlineData 传递 base64 编码后的图像字节。
curl https://api.yourouter.ai/v1/projects/cognition/locations/us/publishers/google/models/gemini-2.5-flash:generateContent \
-H "Authorization: Bearer $YOUROUTER_API_KEY" \
-H "Content-Type: application/json" \
-H "vendor: google" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{ "text": "Describe this image in one sentence." },
{
"inlineData": {
"mimeType": "image/jpeg",
"data": "<BASE64_IMAGE>"
}
}
]
}
]
}'
更完整的集成方式请参考 多模态指南。