Google AI Studio
Google AI Studio ↗ helps you build quickly with Google Gemini models.
Base URL:
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-ai-studioThen you can append the endpoint you want to hit, for example: v1/models/{model}:{generative_ai_rest_resource}
So your final URL will come together as: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-ai-studio/v1/models/{model}:{generative_ai_rest_resource}.
With API Key in Request
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?"} ] } ] }'With Stored Keys (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?"} ] } ] }'If you are using the @google/genai package, you can set your endpoint like this:
With Key in Request
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);With Stored Keys (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);You can also use the OpenAI-compatible endpoint (/ai-gateway/usage/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/completionsSpecify:
{"model": "google-ai-studio/{model}"}Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-