diff --git a/src/utils/api-request.ts b/src/utils/api-request.ts index 4b7170ed68..dbf5d7e2c6 100644 --- a/src/utils/api-request.ts +++ b/src/utils/api-request.ts @@ -1112,6 +1112,15 @@ export class AuthorizedHttp2Client extends Http2Client { const authHeader = 'Authorization'; requestCopy.headers[authHeader] = `Bearer ${token}`; + let quotaProjectId: string | undefined; + if (this.app.options.credential instanceof ApplicationDefaultCredential){ + quotaProjectId = this.app.options.credential.getQuotaProjectId(); + } + quotaProjectId = process.env.GOOGLE_CLOUD_QUOTA_PROJECT || undefined; + if (!requestCopy.headers['x-goog-user-project'] && validator.isNonEmptyString(quotaProjectId)) { + requestCopy.headers['x-goog-user-project'] = quotaProjectId; + } + return super.send(requestCopy); }); }