kaigalmane
kaigalmane

Reputation: 59

Unable to restrict Generative Language API Key on Google Cloud

I have an Android app that uses Generative Language API from Google Cloud. As a best practice, I must restrict my Android app's API key. So I added the package name and SHA-1.

Now, all the calls to API are blocked. I tried with both debug and release keys but none of them worked. I am not sure if Generative Language API supports key restrictions.

Upvotes: 1

Views: 231

Answers (1)

sam
sam

Reputation: 1896

It is recommend that you add both client and API restrictions to all your API keys. Here is an example from https://cloud.google.com/api-keys/docs/add-restrictions-api-keys#add-api-restrictions

gcurl https://apikeys.googleapis.com/v2/projects/PROJECT_NUMBER/locations/global/keys  \
  --request POST \
  --data '{
    "restrictions": {
      "api_targets": [
        {
          "service": "translate.googleapis.com"
        },
        {
          "service" : "datastore.googleapis.com"
        }
      ]
    },
  }'

Upvotes: 0

Related Questions