Skip to content

Commit e033e60

Browse files
committed
Update Google AI Studio SDK example to use gateway base URL
1 parent c76c5bd commit e033e60

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

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

Lines changed: 18 additions & 12 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

6060
const api_token = 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-1.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 genAI = new GoogleGenAI({
65+
apiKey: api_token,
66+
httpOptions: {
67+
baseUrl: `https://gateway.ai.cloudflare.com/v1/${account_id}/${gateway_name}/google-ai-studio`,
68+
},
69+
});
70+
71+
const model = "gemini-1.5-flash";
72+
const prompt = "What is Cloudflare?";
73+
const response = await genAI.models.generateContent({
74+
model,
75+
contents: prompt,
76+
});
77+
78+
console.log(response.text);
7379
```
7480

7581
<Render

0 commit comments

Comments
 (0)