INTEGRITY Dokumentace

Google AI Studio

Google AI Studio vám pomáhá rychle vyvíjet aplikace s modely Google Gemini.

Endpoint

Základní URL adresa:

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-ai-studio

Poté můžete připojit koncový bod, který chcete volat, například: v1/models/{model}:{generative_ai_rest_resource}

Vaše výsledná URL adresa tak bude vypadat takto: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/google-ai-studio/v1/models/{model}:{generative_ai_rest_resource}.

Příklady

cURL

S API klíčem v požadavku

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?"}
            ]
          }
        ]
      }'

S uloženými klíči (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

Pokud používáte @google/genai balíček, můžete nastavit svůj endpoint takto:

S klíčem v požadavku

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);

S uloženými klíči (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);

Koncový bod kompatibilní s OpenAI

K modelům Google AI Studio můžete přistupovat také pomocí schématu OpenAI API prostřednictvím REST API. Odesílejte své požadavky na:

https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions

Zadejte:


{
"model": "google-ai-studio/{model}"
}