Skip to content

[Bug] (FirebaseAI) - "x-ios-bundle-identifier" header is not added in the GenerativeAIRequest urlRequest #15475

@psbpd21

Description

@psbpd21

Description

HI i'm trying to enable API Key application restriction but with no avail since the GenerativeAIService urlRequest lack the "x-ios-bundle-identifier". After i added the header in this function: private func urlRequest<T: GenerativeAIRequest>(request: T) async throws -> URLRequest {}, the application restriction worked.

Reproducing the issue

  1. Edit the API Key that was used for Firebase AI Logic API and Generative Language API in google cloud console.
  2. Enable application restrictions with your app bundle id.
  3. Send a generateContent request.

Firebase SDK Version

12.3

Xcode Version

26.0.1

Installation Method

CocoaPods

Firebase Product(s)

AI Logic

Targeted Platforms

iOS

Relevant Log Output

GenerateContentError
  ▿ internalError : 1 element
    ▿ underlying : BackendError
      - httpResponseCode : 403
      - message : "Requests from this iOS client application <empty> are blocked."
      - status : FirebaseAI.RPCStatus.permissionDenied
      ▿ details : 2 elements
        ▿ 0 : ErrorDetails
          - type : "type.googleapis.com/google.rpc.ErrorInfo"
          ▿ reason : Optional<String>
            - some : "API_KEY_IOS_APP_BLOCKED"
          ▿ domain : Optional<String>
            - some : "googleapis.com"
          ▿ metadata : Optional<Dictionary<String, String>>
            ▿ some : 3 elements
              ▿ 0 : 2 elements
                - key : "service"
                - value : "firebasevertexai.googleapis.com"
              ▿ 1 : 2 elements
                - key : "iosBundleId"
                - value : "<empty>"
              ▿ 2 : 2 elements
                - key : "consumer"
                - value : redacted
        ▿ 1 : ErrorDetails
          - type : "type.googleapis.com/google.rpc.LocalizedMessage"
          - reason : nil
          - domain : nil
          - metadata : nil

If using Swift Package Manager, the project's Package.resolved

If using CocoaPods, the project's Podfile.lock

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions