From 7d3180c773b87782f8a8d78e472b567d75fef238 Mon Sep 17 00:00:00 2001 From: Palash Golecha Date: Thu, 30 Oct 2025 20:30:20 +0530 Subject: [PATCH] fix: google-ai-studio example, dyn routing metadata --- .../features/dynamic-routing/usage.mdx | 8 +++++ .../usage/providers/google-ai-studio.mdx | 32 +++++++++++-------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/content/docs/ai-gateway/features/dynamic-routing/usage.mdx b/src/content/docs/ai-gateway/features/dynamic-routing/usage.mdx index aeaea275aa7d51..1ffa924f3cb5a9 100644 --- a/src/content/docs/ai-gateway/features/dynamic-routing/usage.mdx +++ b/src/content/docs/ai-gateway/features/dynamic-routing/usage.mdx @@ -86,3 +86,11 @@ export default { }, }; ``` + +## Response Metadata + +The response from a dynamic route is the same as the response from a model. There is additional metadata used to notify the model and provider used, you can check the following headers + +- `cf-aig-model` - The model used +- `cf-aig-provider` - The slug of provider used + diff --git a/src/content/docs/ai-gateway/usage/providers/google-ai-studio.mdx b/src/content/docs/ai-gateway/usage/providers/google-ai-studio.mdx index a61ac71446789f..ebccaf985182e5 100644 --- a/src/content/docs/ai-gateway/usage/providers/google-ai-studio.mdx +++ b/src/content/docs/ai-gateway/usage/providers/google-ai-studio.mdx @@ -50,26 +50,32 @@ curl "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/google-ai }' ``` -### Use `@google/generative-ai` with JavaScript +### Use `@google/genai` with JavaScript -If you are using the `@google/generative-ai` package, you can set your endpoint like this: +If you are using the `@google/genai` package, you can set your endpoint like this: ```js title="JavaScript example" -import { GoogleGenerativeAI } from "@google/generative-ai"; +import { GoogleGenAI } from "@google/genai"; -const api_token = env.GOOGLE_AI_STUDIO_TOKEN; +const apiKey = env.GOOGLE_AI_STUDIO_TOKEN; const account_id = ""; const gateway_name = ""; -const genAI = new GoogleGenerativeAI(api_token); -const model = genAI.getGenerativeModel( - { model: "gemini-2.5-flash" }, - { - baseUrl: `https://gateway.ai.cloudflare.com/v1/${account_id}/${gateway_name}/google-ai-studio`, - }, -); - -await model.generateContent(["What is Cloudflare?"]); +const ai = new GoogleGenAI({ + apiKey, +}); + +const response = await ai.models.generateContent({ + model: "gemini-2.5-flash", + contents: "What is Cloudflare?", + config: { + httpOptions: { + baseUrl: `https://gateway.ai.cloudflare.com/v1/${account_id}/${gateway_name}/google-ai-studio`, + }, + }, +}); + +console.log(response.text); ```