Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dlarocque
Copy link
Contributor

@dlarocque dlarocque commented Feb 25, 2025

Do not merge.

  • Add a X-Firebase-AppId header containing the App ID to VertexAI requests.
  • Add appId to ApiSettings, and throw an error if it's not defined when initializing the VertexAI instance.

In my testing, the browser converted X-Firebase-AppId to X-Firebase-Appid (lowercases i) in the request. Would this cause any issues?

Copy link

changeset-bot bot commented Feb 25, 2025

🦋 Changeset detected

Latest commit: 767cd77

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@firebase/vertexai Patch
firebase Patch

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 25, 2025

Size Report 1

Affected Products

  • @firebase/vertexai

    TypeBase (dcfb3da)Merge (bd5a213)Diff
    browser34.0 kB34.5 kB+500 B (+1.5%)
    main34.9 kB35.4 kB+500 B (+1.4%)
    module34.0 kB34.5 kB+500 B (+1.5%)
  • firebase

    TypeBase (dcfb3da)Merge (bd5a213)Diff
    firebase-vertexai.js27.6 kB28.1 kB+449 B (+1.6%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/zpTvRtT8a8.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 25, 2025

Size Analysis Report 1

Affected Products

  • @firebase/vertexai

    • ChatSession

      Size

      TypeBase (dcfb3da)Merge (bd5a213)Diff
      size15.5 kB15.6 kB+106 B (+0.7%)
      size-with-ext-deps34.4 kB34.5 kB+106 B (+0.3%)
    • GenerativeModel

      Size

      TypeBase (dcfb3da)Merge (bd5a213)Diff
      size18.2 kB18.7 kB+449 B (+2.5%)
      size-with-ext-deps37.2 kB37.7 kB+450 B (+1.2%)
    • ImagenModel

      Size

      TypeBase (dcfb3da)Merge (bd5a213)Diff
      size9.41 kB9.86 kB+449 B (+4.8%)
      size-with-ext-deps27.4 kB27.9 kB+450 B (+1.6%)
    • VertexAIModel

      Size

      TypeBase (dcfb3da)Merge (bd5a213)Diff
      size4.67 kB5.01 kB+343 B (+7.3%)
      size-with-ext-deps22.6 kB23.0 kB+344 B (+1.5%)
    • getGenerativeModel

      Size

      TypeBase (dcfb3da)Merge (bd5a213)Diff
      size18.4 kB18.9 kB+449 B (+2.4%)
      size-with-ext-deps37.4 kB37.8 kB+450 B (+1.2%)
    • getImagenModel

      Size

      TypeBase (dcfb3da)Merge (bd5a213)Diff
      size9.57 kB10.0 kB+449 B (+4.7%)
      size-with-ext-deps27.6 kB28.0 kB+450 B (+1.6%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/83UJzno9Fh.html

@hsubox76
Copy link
Contributor

In my testing, the browser converted X-Firebase-AppId to X-Firebase-Appid (lowercases i) in the request. Would this cause any issues?

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(
Copy link
Contributor

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.

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(

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.

@dlarocque dlarocque requested a review from paulb777 February 25, 2025 19:17
Copy link
Member

@paulb777 paulb777 left a 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:
Copy link
Contributor

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) {
Copy link
Contributor

@hsubox76 hsubox76 Feb 27, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants