Skip to content

Commit 06c90eb

Browse files
committed
Re-patch google-vertex for AI SDK v6
1 parent 50a2435 commit 06c90eb

4 files changed

Lines changed: 24 additions & 43 deletions

File tree

.changeset/wicked-eggs-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ai-gateway-provider": patch
3+
---
4+
5+
Fix google-vertex BYOK/Unified Billing support

packages/ai-gateway-provider/src/providers/google-vertex.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { createVertex as createVertexOriginal } from "@ai-sdk/google-vertex/edge
22
import { CF_TEMP_TOKEN } from "../auth";
33

44
export const createVertex = (...args: Parameters<typeof createVertexOriginal>) => {
5-
const [config] = args;
6-
// In v6, apiKey is a top-level property for express mode authentication
7-
const configWithApiKey = {
8-
...config,
9-
apiKey: config?.apiKey ?? CF_TEMP_TOKEN,
10-
};
11-
return createVertexOriginal(configWithApiKey);
12-
};
5+
let [config] = args;
6+
if (config === undefined) {
7+
config = { googleCredentials: { cfApiKey: CF_TEMP_TOKEN } } as any;
8+
}
9+
// no google credentials and no express mode apikey
10+
else if (config.googleCredentials === undefined && config.apiKey === undefined) {
11+
config.googleCredentials = { cfApiKey: CF_TEMP_TOKEN } as any;
12+
}
13+
return createVertexOriginal(config);
14+
}
Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,24 @@
1-
diff --git a/dist/edge/index.d.mts b/dist/edge/index.d.mts
2-
index a8fea73f05364d1b67b91d547bf76007275bea57..a4496464e0dc05eb514a6085c2e1d79849271886 100644
3-
--- a/dist/edge/index.d.mts
4-
+++ b/dist/edge/index.d.mts
5-
@@ -100,7 +100,7 @@ interface GoogleVertexProviderSettings extends GoogleVertexProviderSettings$1 {
6-
* not provided, the Google Vertex provider will use environment variables to
7-
* load the credentials.
8-
*/
9-
- googleCredentials?: GoogleCredentials;
10-
+ googleCredentials?: GoogleCredentials | { apiKey: string };
11-
}
12-
declare function createVertex(options?: GoogleVertexProviderSettings): GoogleVertexProvider;
13-
/**
14-
diff --git a/dist/edge/index.d.ts b/dist/edge/index.d.ts
15-
index a8fea73f05364d1b67b91d547bf76007275bea57..a4496464e0dc05eb514a6085c2e1d79849271886 100644
16-
--- a/dist/edge/index.d.ts
17-
+++ b/dist/edge/index.d.ts
18-
@@ -100,7 +100,7 @@ interface GoogleVertexProviderSettings extends GoogleVertexProviderSettings$1 {
19-
* not provided, the Google Vertex provider will use environment variables to
20-
* load the credentials.
21-
*/
22-
- googleCredentials?: GoogleCredentials;
23-
+ googleCredentials?: GoogleCredentials | { apiKey: string };
24-
}
25-
declare function createVertex(options?: GoogleVertexProviderSettings): GoogleVertexProvider;
26-
/**
271
diff --git a/dist/edge/index.js b/dist/edge/index.js
28-
index 8d155c95c62b177e232811dab69e78ba02f406d0..988ad94b9fcf4cd1123f1bec1700b83d3e7e3e32 100644
2+
index 079ab83ed4518113abdc847cc2f644a654a656ec..beffbc925b35aea015d27e936cf5208bcbcc9c8b 100644
293
--- a/dist/edge/index.js
304
+++ b/dist/edge/index.js
31-
@@ -457,6 +457,7 @@ var buildJwt = async (credentials) => {
5+
@@ -587,6 +587,7 @@ var buildJwt = async (credentials) => {
326
};
337
async function generateAuthToken(credentials) {
348
try {
35-
+ if(credentials.apiKey) return credentials.apiKey;
9+
+ if(credentials.cfApiKey) return credentials.cfApiKey;
3610
const creds = credentials || await loadCredentials();
3711
const jwt = await buildJwt(creds);
3812
const response = await fetch("https://oauth2.googleapis.com/token", {
3913
diff --git a/dist/edge/index.mjs b/dist/edge/index.mjs
40-
index 330c98783ca74cb3b87e22370889a21b7a11f5dd..0fe244acc9a7381eb1c78610f17f68f12d08881a 100644
14+
index 89a0c0ef49b4beaa1d53fdff49f1dea93333dc8a..be6988f70fc17c058183c17da2fd9f1a9a9dee26 100644
4115
--- a/dist/edge/index.mjs
4216
+++ b/dist/edge/index.mjs
43-
@@ -455,6 +455,7 @@ var buildJwt = async (credentials) => {
17+
@@ -587,6 +587,7 @@ var buildJwt = async (credentials) => {
4418
};
4519
async function generateAuthToken(credentials) {
4620
try {
47-
+ if(credentials.apiKey) return credentials.apiKey;
21+
+ if(credentials.cfApiKey) return credentials.cfApiKey;
4822
const creds = credentials || await loadCredentials();
4923
const jwt = await buildJwt(creds);
5024
const response = await fetch("https://oauth2.googleapis.com/token", {

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)