Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

GoogleGenerativeAIError: ACCESS_TOKEN_SCOPE_INSUFFICIENT

Hi Community,

I'm encountering an error while attempting to make a POST request to the Google Generative Language API. I’m working on a project that requires embedding text using the embedding-001 model. Below are the details:
Screenshot of the all the roles provided and enabled for service account:

sidsanc_0-1729616677311.png

  • Issue: I'm trying to embed text using the Google Generative AI API, but I keep receiving the following error:

 

 

{
  "error": {
    "code": 403,
    "message": "Request had insufficient authentication scopes.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT",
        "domain": "googleapis.com",
        "metadata": {
          "method": "google.ai.generativelanguage.v1beta.GenerativeService.BatchEmbedContents",
          "service": "generativelanguage.googleapis.com"
        }
      }
    ]
  }
}

 

 

What I've tried so far:

  • I’ve generated a service account key and added the necessary scopes for Generative Language API:

 

 

scopes = ["https://www.googleapis.com/auth/generative-language"]
​

 

 

  • I’ve used the following authentication method:

 

 

credentials = service_account.Credentials.from_service_account_file(
    service_account_key_path, scopes=scopes
)
credentials.refresh(Request())
​

 

 

  • The access token seems to be generated correctly, but the API call fails with insufficient scope permissions.

    Error Response: Despite following the official documentation, I continue to receive the ACCESS_TOKEN_SCOPE_INSUFFICIENT error. I’ve verified the service account and scopes multiple times.

    Questions:

    • Am I missing any specific permissions or scopes for the Generative AI API?
    • Is there any additional configuration required for embedding text using the embedding-001 model?

 



1 1 2,646