tristantao/py-ms-cognitive

Method to retrieve remaining API credits

Opened this issue · 2 comments

Would be handy to have a method to retrieve the remaining API credits for an account.

That makes sense.

Unfortunately I can't find an API offering from Microsoft that allows for that. Let me know if you know of an endpoint / doc they offer that allows the users to get remaining credits.

I'm pretty familiar with the Azure RM interface and this issue is probably not practical to solve. :[

In order to accomplish this in python one would need to use the azure resource-manager (pip install azurerm). The API-key you use here gives you access to a single, specific REST interface for interacting with the search engine. Since controls for & statistics on your various Azure-resources are implemented at the subscription-level, the API-key you're currently using with this package would not be sufficient to authenticate you.
This is primarily due to some prep-work necessary to use azurerm in the first place:

To use the azurerm python SDK you need to integrate an "app" with Azure Active Directory:

To see your usage statistics outside of the Azure Dashboard you'll need to either use PowerShell (which has authentication baked-in to it's SDK,) or register some sort of authentication-mechanism with your AAD tenant. The easiest way to do this is to register a "service principal" via the Azure Active Directory pane at https://portal.azure.com. This will give you 3 new "keys" needed each time you want to authenticate:

  • the "app"'s tenant id.
  • your Azure subscription-ID
  • a secret code it gives you at registration time.

after that...welll there's probably some rabbit-hole of commands which would find that specific piece of info. It's probably somewhere in here: https://github.com/Azure/azure-sdk-for-python/tree/master/azure-mgmt-cognitiveservices