← Cloudflare AI Gateway / ai-gateway / usage / providers
Google AI Studio
Google AI Studio ↗ помогает быстро создавать приложения на основе моделей Google Gemini.
Конечная точка
Базовый 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
С API-ключом в запросе
curl "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/google-ai-studio/v1/models/gemini-2.5-flash:generateContent" \
--header 'content-type: application/json' \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'x-goog-api-key: {google_studio_api_key}' \
--data '{
"contents": [
{
"role":"user",
"parts": [
{"text":"What is Cloudflare?"}
]
}
]
}'curl "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/google-ai-studio/v1/models/gemini-2.5-flash:generateContent" \
--header 'content-type: application/json' \
--header 'x-goog-api-key: {google_studio_api_key}' \
--data '{
"contents": [
{
"role":"user",
"parts": [
{"text":"What is Cloudflare?"}
]
}
]
}'С сохранёнными ключами (BYOK) / Unified Billing
curl "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/google-ai-studio/v1/models/gemini-2.5-flash:generateContent" \
--header 'content-type: application/json' \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--data '{
"contents": [
{
"role":"user",
"parts": [
{"text":"What is Cloudflare?"}
]
}
]
}'@google/genai
Если вы используете @google/genai пакет, вы можете настроить конечную точку следующим образом:
С ключом в запросе
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({
apiKey: "{google_studio_api_key}",
httpOptions: {
baseUrl: `https://gateway.ai.cloudflare.com/v1/${account_id}/${gateway_name}/google-ai-studio`,
headers: {
'cf-aig-authorization': 'Bearer {cf_aig_token}',
}
}
});
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: "What is Cloudflare?",
});
console.log(response.text);import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({
apiKey: "{google_studio_api_key}",
httpOptions: {
baseUrl: `https://gateway.ai.cloudflare.com/v1/${account_id}/${gateway_name}/google-ai-studio`,
}
});
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: "What is Cloudflare?",
});
console.log(response.text);С сохранёнными ключами (BYOK) / Unified Billing
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({
apiKey: "{cf_aig_token}",
httpOptions: {
baseUrl: `https://gateway.ai.cloudflare.com/v1/${account_id}/${gateway_name}/google-ai-studio`,
}
});
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: "What is Cloudflare?",
});
console.log(response.text);OpenAI-совместимый эндпойнт
Вы также можете обращаться к моделям Google AI Studio через схему OpenAI API, используя REST API. Отправляйте свои запросы на:
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completionsУкажите:
{
"model": "google-ai-studio/{model}"
}