Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

AI platform ADC issue

I have a function uses:

```python

aiplatform.init(project=PROJECT_ID, location=LOCATION)
vertexai.init(project=PROJECT_ID, location=LOCATION)
self.text_embedding_model = TextEmbeddingModel.from_pretrained("text-embedding-004")
```
 
It runs perfectly fine in the local machine but when I paste the code to cloud function and test it, it throws
 
```
google.api_core.exceptions.PermissionDenied: 403 Your application is authenticating by using local Application Default Credentials. The aiplatform.googleapis.com API requires a quota project..
```
 
Is there any fix I can do to fix this??
I have been struggling for three days
 
0 1 200
1 REPLY 1

Hi @Mashishi,

Welcome to Google Cloud Community!

For Application Default Credentials error, you may check out this documentation that can help you fix this. In addition, make sure that your default quota project for Cloud Functions is set to the correct project. As mentioned in the docs, when you provide user credentials to authenticate to a client-based API, you must specify the project to use for billing and quota.

You can try setting the quota project when getting default credentials and passing these to the Vertex AI SDK. See sample code below:

import vertexai
import google.auth
from vertexai.language_models import TextEmbeddingModel

credentials, _ = google.auth.default(quota_project_id='YOUR_PROJECT_ID')
vertexai.init(project='YOUR_PROJECT_ID', creds=credentials)
model = TextEmbeddingModel.from_pretrained(MODEL_ID)

Hope this helps.