Skip to content

Commit 7d3180c

Browse files
committed
fix: google-ai-studio example, dyn routing metadata
1 parent ef64243 commit 7d3180c

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/content/docs/ai-gateway/features/dynamic-routing/usage.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,11 @@ export default {
8686
},
8787
};
8888
```
89+
90+
## Response Metadata
91+
92+
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
93+
94+
- `cf-aig-model` - The model used
95+
- `cf-aig-provider` - The slug of provider used
96+

src/content/docs/ai-gateway/usage/providers/google-ai-studio.mdx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,32 @@ curl "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/google-ai
5050
}'
5151
```
5252

53-
### Use `@google/generative-ai` with JavaScript
53+
### Use `@google/genai` with JavaScript
5454

55-
If you are using the `@google/generative-ai` package, you can set your endpoint like this:
55+
If you are using the `@google/genai` package, you can set your endpoint like this:
5656

5757
```js title="JavaScript example"
58-
import { GoogleGenerativeAI } from "@google/generative-ai";
58+
import { GoogleGenAI } from "@google/genai";
5959

60-
const api_token = env.GOOGLE_AI_STUDIO_TOKEN;
60+
const apiKey = env.GOOGLE_AI_STUDIO_TOKEN;
6161
const account_id = "";
6262
const gateway_name = "";
6363

64-
const genAI = new GoogleGenerativeAI(api_token);
65-
const model = genAI.getGenerativeModel(
66-
{ model: "gemini-2.5-flash" },
67-
{
68-
baseUrl: `https://gateway.ai.cloudflare.com/v1/${account_id}/${gateway_name}/google-ai-studio`,
69-
},
70-
);
71-
72-
await model.generateContent(["What is Cloudflare?"]);
64+
const ai = new GoogleGenAI({
65+
apiKey,
66+
});
67+
68+
const response = await ai.models.generateContent({
69+
model: "gemini-2.5-flash",
70+
contents: "What is Cloudflare?",
71+
config: {
72+
httpOptions: {
73+
baseUrl: `https://gateway.ai.cloudflare.com/v1/${account_id}/${gateway_name}/google-ai-studio`,
74+
},
75+
},
76+
});
77+
78+
console.log(response.text);
7379
```
7480

7581
<Render

0 commit comments

Comments
 (0)