Google AI Studio
Last updated Apr 20, 2026 helps you build quickly with Google Gemini models.
Endpoint
Base URL:
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-ai-studio
Then 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}.
Examples
cURL
<details>
<summary>
With API Key in Request
</summary>
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?"}
]
}
]
}'
</details>
<details>
<summary>
With Stored Keys (BYOK) / Unified Billing
</summary>
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?"}
]
}
]
}'
</details>
@google/genai
If you are using the @google/genai package, you can set your endpoint like this:
<details>
<summary>
With Key in Request
</summary>
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);
</details>
<details>
<summary>
With Stored Keys (BYOK) / Unified Billing
</summary>
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);
</details>
OpenAI-Compatible Endpoint
You can also access Google AI Studio models using the OpenAI API schema through the REST API. Send your requests to:
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions
Specify:
{
"model": "google-ai-studio/{model}"
}
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ai-gateway/usage/providers/google-ai-studio/#page","headline":"Google AI Studio","description":"Route Google AI Studio and Gemini requests through AI Gateway for observability and control.","url":"https://developers.cloudflare.com/ai-gateway/usage/providers/google-ai-studio/","inLanguage":"en","image":"https://developers.cloudflare.com/ai-gateway/usage/providers/google-ai-studio/og.png?v=3cc8a49846d345ce","dateModified":"2026-04-20","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Route xAI (Grok) API requests through AI Gateway for observability and control. title: xAI image: https://developers.cloudflare.com/ai-gateway/usage/providers/grok/og.png?v=de1686aef0ce6ab1
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/ai-gateway/llms.txt
Use this file to discover all available pages before exploring further.
Docs