Google Cloud Translate V3 Java - PERMISSION_DENIED: Cloud IAM permission 'cloudtranslate.generalModels.predict' denied

Viewed 980

I have one project in google cloud, already using speech APIs successfully. I am the only user and I have Owner permissions over the service. My account is connected to billing. The environment credentials is set and working properly with other services. I'm using Java SDK v3 (advanced translation).

When running translation in java I get PERMISSION_DENIED: Cloud IAM permission 'cloudtranslate.generalModels.predict' denied.

try (TranslationServiceClient client = TranslationServiceClient.create()) {

            // projects/MY_PROJECT_ID/locations/global
            LocationName parent = LocationName.of("MY_PROJECT_ID", "global");

            // projects/MY_PROJECT_ID/locations/global/models/general/base
            String model = parent.toString() +  "/models/general/base";
            
            TranslateTextRequest request =
                    TranslateTextRequest.newBuilder()
                            .setParent(parent.toString())
                            .setMimeType("text/plain")
                            .setSourceLanguageCode("he")
                            .setTargetLanguageCode("en")
                            .setModel(model)
                            .addContents(source)
                            .build();

            TranslateTextResponse response = client.translateText(request);

            for (Translation translation : response.getTranslationsList()) {
                System.out.printf("Translated text: %s\n", translation.getTranslatedText());
            }
        }

Please advise :)

0 Answers
Related