How i fixed "Getting metadata from plugin failed with error: invalid_grant"

cloud GCP vision

I experimeneted with Google Cloud Vision in Node.js and ran this code:

const vision = require('@google-cloud/vision');
const client = new vision.ImageAnnotatorClient();

const fileName = './image.jpg';

    .then(result => {
        result[0].labelAnnotations.forEach(element => {
    .catch(err => console.log(err));

In the terminal I got:

{ Error: 400 undefined: Getting metadata from plugin failed with error: invalid_grant
    at ...
  code: '400',
   'Getting metadata from plugin failed with error: invalid_grant',
  metadata: Metadata { internalRepr: Map {}, options: {} },
   'Exception occurred in retry method that was not classified as transient' }


This error means that you don’t have a JSON file with service account key OR your session with the path was expired.

No service account key

If you assume it’s the first issue and you need to get your service account key, please check my post about how I fixed the error about “The incoming JSON object does not contain a client_email field”. This post contains a part about getting a service account key in Google Cloud.

Expired session

For example, you already exported path with:


but you face this issue. You just need to rerun this command again, because it applies to the terminal session. If you close the terminal, PATH will expire.

comments powered by Disqus