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 AI Translator
Azure AI Translator
An Azure service to easily conduct machine translation with a simple REST API call.
{count} votes

Your answer

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