I'm trying to authenticate with the Vertex AI Generative AI API in my google cloud function. I can see that both have the same service account attached to them. So I thought that authentication will not be necessary since it would be done implicitly so I didn't include any authorization headers. However I'm getting a 401 error in my logs which indicates a lack of auth credentials. How do I get these auth credentials? I'm using the code below to communicate with the API:
const headers = {
'Content-Type': 'application/json'
};
const chatparams = {
instances: {
context: "",
examples: [],
messages: [{
"author": "user",
"content": "how do i talk to you"
}]
},
parameters: {
temperature: 0.2,
maxOutputTokens: maxtokens,
topP: 0.8,
topK: 40
}
};
// eslint-disable-next-line promise/no-nesting
return axios.create({headers}).post("https://us-central1-aiplatform.googleapis.com/v1/projects/projectname/locations/us-central1/publishers/google/models/chat-bison@001:predict", chatparams).then(result => {
return result.data;
}
).catch(error => {
console.log('error in getting data from chatgpt is ' + error);
})