I use the GCP Text-to-Speech API to create greetings and interactive menus that are played to phone customers who call into businesses. I have successfully used the Text-to-Speech API in the past using this Google quick-start: Google Cloud Text-to-Speech I used the same quick-start guide again for a new organization and project but I keep getting an invalid key error which I have been unable to debug. Here are the commands I have used to invoke the service and the results:
# curl -X POST \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)”\
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
https://texttospeech.googleapis.com/v1/text:synthesize > synthesize-output-base64.txt
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"
}
}
I tried again with a different authentication header:
# curl -X POST \
-H "X-Goog-Api-Key:***my_API_key***.json" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
https://texttospeech.googleapis.com/v1/text:synthesize > synthesize-output-base64.txt
{
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_INVALID",
"domain": "googleapis.com",
"metadata": {
"service": "texttospeech.googleapis.com"
}
}
]
}
}
I have re-verified the following configurations:
The Text-to-Speech API is enabled for my project.
The credential (service account) I am attempting to use is listed with the Text-to-Speech API as compatible. I verified that that service account key is the key that was used in the attempted authentications.
I compared my configuration on GCP with another working configuration I manage for a different company. There are no differences I can see.
I compared my key and the other company's working key and they are identical except for the specific user data.
The billing account for the project is active with valid payment card in place.
These two links were helpful but did not clear up the problem: Google Cloud Text-to-Speech API - permission error Google Cloud Text to Speech INVALID API KEY
Any help on this issue would be very appreciated!
gcloud auth application-default print-access-tokenis actually returning a valid OAuth Access Token. For your second example, this is not correct-H "X-Goog-Api-Key:***my_API_key***.json"Is the.jsonending a typo? If yes, correct your details. - John Hanleyya29.. (four characters and a period). For your first example, I recommend assigning the token creation output to a shell variable and then using that as your Bearer token. Helps with debugging. - John Hanleycurl -H "Authorization: Bearer TOKEN" https://www.googleapis.com/oauth2/v3/tokeninfo- John Hanley***my_API_key***is where I put my actual key. I probably could have made a better choice of how to hide my key...The error code I am getting says I have an invalid key. Is there some configuration error I probably have made in setting this up? - bruce57