Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

32 changes: 19 additions & 13 deletions src/content/docs/ai-gateway/usage/providers/google-ai-studio.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```

<Render
Expand Down