openai-go icon indicating copy to clipboard operation
openai-go copied to clipboard

[Azure] Wrong scope used for Azure Gov

Open jgeralnik opened this issue 2 months ago • 0 comments

When connecting to Azure government environment I get an error:

Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.us/ or https://ai.azure.us/), or have expired

This is because the scopes are hardcoded tohttps://cognitiveservices.azure.com/.default in WithTokenCredential.

It's a bit annoying to solve without breaking the API because WithTokenCredential doesn't have the proper context to know if we are connecting to a gov environment. What I'd really like is to pass in an azcore.ClientOptions object that has a Cloud field (and then compare it to azcore/cloud.AzureGovernment) or something like that, although I would settle for anything that lets me configure it, even a new WithTokenCredentialWithCustomScope function that lets me pass in the tokenScope myself.

(Presumably this is also an issue for Azure China, although I'm not using that so I can't say)

jgeralnik avatar Oct 08 '25 12:10 jgeralnik