Google AI Studio ↗ 帮助您使用 Google Gemini 模型快速构建。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-ai-studio
在向 Google AI Studio 发出请求时,您需要:
- 您的 AI 网关账户 ID。
- 您的 AI 网关网关名称。
- 一个有效的 Google AI Studio API 令牌。
- 您要使用的 Google AI Studio 模型的名称。
您的新基础 URL 将使用上述数据的结构:https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-ai-studio/
。
然后您可以附加您要访问的端点,例如:v1/models/{model}:{generative_ai_rest_resource}
因此您的最终 URL 将组合为:https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-ai-studio/v1/models/{model}:{generative_ai_rest_resource}
。
curl "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/google-ai-studio/v1/models/gemini-1.0-pro:generateContent" \ --header 'content-type: application/json' \ --header 'x-goog-api-key: {google_studio_api_key}' \ --data '{ "contents": [ { "role":"user", "parts": [ {"text":"What is Cloudflare?"} ] } ] }'
如果您使用 @google/generative-ai
包,您可以这样设置您的端点:
import { GoogleGenerativeAI } from "@google/generative-ai";
const api_token = env.GOOGLE_AI_STUDIO_TOKEN;const account_id = "";const gateway_name = "";
const genAI = new GoogleGenerativeAI(api_token);const model = genAI.getGenerativeModel( { model: "gemini-1.5-flash" }, { baseUrl: `https://gateway.ai.cloudflare.com/v1/${account_id}/${gateway_name}/google-ai-studio`, },);
await model.generateContent(["What is Cloudflare?"]);
You can also use the OpenAI-compatible endpoint (/ai-gateway/chat-completion/
) to access Google AI Studio models using the OpenAI API schema. To do so, send your requests to:
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions
Specify:
{"model": "google-ai-studio/{model}"}
- @2025 Cloudflare Ubitools
- Cf Repo