Translator Java SDK fails with "{"error":{"code":401001,"message":"The request is not authorized because credentials are missing or invalid."}}"

Jason Bodnar 0 Reputation points
2024-11-18T23:03:29.94+00:00

Using the Java SDK, I keep getting "{"error":{"code":401001,"message":"The request is not authorized because credentials are missing or invalid."}}". I've tried adding the tenantId, the endpoint URL, the resourceId, etc. I'm logged into the appropriate subscription using the Azure cli.

@Bean
public TextTranslationClient textTranslationClient() {
    return new TextTranslationClientBuilder()
            .credential(new DefaultAzureCredentialBuilder()
                                .build())
            .buildClient();
    }
TranslatedTextItem translatedTextItem = textTranslationClient.translate(text, new TranslateOptions().setTargetLanguages(SUPPORTED_LANGUAGES));
Azure Translator
Azure Translator
An Azure service to easily conduct machine translation with a simple REST API call.
427 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.