-
Notifications
You must be signed in to change notification settings - Fork 912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add X-Firebase-AppId
header to VertexAI requests
#8809
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 767cd77 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size Report 1Affected Products
Test Logs |
Size Analysis Report 1Affected Products
Test Logs |
It's fine, according to HTTP standard, headers are case insensitive, I guess we just capitalize for better readability in code. |
@@ -68,10 +68,16 @@ export abstract class VertexAIModel { | |||
VertexAIErrorCode.NO_PROJECT_ID, | |||
`The "projectId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid project ID.` | |||
); | |||
} else if (!vertexAI.app?.options?.appId) { | |||
throw new VertexAIError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In light of Paul's comment about automaticDataCollectionEnabled
, not sure if we throw this error if that's false, since we don't actually need appId in that case? Kind of weird edge case though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The firebaseAppConfig
obtained from Firebase Console and Terraform always contains an appId
, so unless the developer deliberately removes the appId
(not sure why since it's not sensitive), it should always be present. AppId is not just for telemetry purposes. Thus, stronger validation is better here.
@@ -68,10 +68,16 @@ export abstract class VertexAIModel { | |||
VertexAIErrorCode.NO_PROJECT_ID, | |||
`The "projectId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid project ID.` | |||
); | |||
} else if (!vertexAI.app?.options?.appId) { | |||
throw new VertexAIError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The firebaseAppConfig
obtained from Firebase Console and Terraform always contains an appId
, so unless the developer deliberately removes the appId
(not sure why since it's not sensitive), it should always be present. AppId is not just for telemetry purposes. Thus, stronger validation is better here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, please wait for privacy review process before releasing the header change.
Thanks!
@@ -78,6 +78,8 @@ export abstract class VertexAIModel { | |||
apiKey: vertexAI.app.options.apiKey, | |||
project: vertexAI.app.options.projectId, | |||
appId: vertexAI.app.options.appId, | |||
automaticDataCollectionEnabled: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No action needed, just wondering out loud if at some number of properties, we just pass vertexAI.app or at least vertexAI.app.options through instead of passing them through one by one.
@@ -84,7 +84,9 @@ export async function getHeaders(url: RequestUrl): Promise<Headers> { | |||
headers.append('Content-Type', 'application/json'); | |||
headers.append('x-goog-api-client', getClientHeaders()); | |||
headers.append('x-goog-api-key', url.apiSettings.apiKey); | |||
headers.append('X-Firebase-AppId', url.apiSettings.appId); // Will be converted to 'X-Firebase-Appid' before it's sent in the browser. | |||
if (url.apiSettings.automaticDataCollectionEnabled !== false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should be safe and make this fail on any falsy value in case, say, the user sets it to undefined for some reason. Sometimes that's how people unset properties. So just if (url.apiSettings.automaticDataCollectionEnabled)
? I do think this is a very edge case, so consider it a nit.
Do not merge.
X-Firebase-AppId
header containing the App ID to VertexAI requests.appId
toApiSettings
, and throw an error if it's not defined when initializing the VertexAI instance.In my testing, the browser convertedX-Firebase-AppId
toX-Firebase-Appid
(lowercasesi
) in the request. Would this cause any issues?