0

I'm working on a project on gcp using the OCR service from Google Vision. My code is simple, I've declared a vision ImageAnnotatorClient like this:

client = vision.ImageAnnotatorClient()

and then call some batch annotation request like this:

response = client.batch_annotate_images(requests=[....])

There is a way to know which project will be used for the billing of the requests? I've not explicitly set the credential and, in this case, the documentation (https://googleapis.dev/python/vision/latest/vision_v1/image_annotator.html) says that

if none are specified, the client will attempt to ascertain the credentials from the environment.

I need to know what "ascertain the credentials from the environment" means in this case, since I've alrteady done some requests and I wold like to know on which of the projects I'm working right now the requests will be charged.

CopyPaster
  • 21
  • 3
  • Google search for ADC - Application Default Credentials. Most likely your application is using the credentials you set up when you initialized the Google Cloud CLI (gcloud). The CLI can set/get the default project: https://cloud.google.com/sdk/gcloud/reference/config/set – John Hanley Jun 09 '22 at 19:34
  • Also, see my answer about the quota project: https://stackoverflow.com/a/63713409/8016720 – John Hanley Jun 09 '22 at 19:42
  • I've already checked for the default project and I've seen some visions costs in the project that I have as default, so it seems plausible. The problem is that right now I have to run the same code on a large bunch of images so I need to be sure and I cant find references in the documentations. Thank you for the response, I'll investigate more on ADC. @JohnHanley – CopyPaster Jun 09 '22 at 19:58
  • You can always declare the credentials to use instead of letting the system select one. – John Hanley Jun 09 '22 at 20:13
  • ok, I've found the right methodology to check the credential used in this case. The code as written above uses _get_explicit_environ_credentials() in google.auth._default as first. If the service account is set the project will be the one relative to the SA. If not set _get_gcloud_sdk_credentials() will be used, so the default project from CLI is used. If you want to be sure what project is used is sufficient to get one of this two inside your code, depending on the case. So it seems that setting GOOGLE_APPLICATION_CREDENTIALS env var is sufficient. – CopyPaster Jun 10 '22 at 08:43

0 Answers0