viane / microsoft-computer-vision

A simple NodeJS wrapper package for Microsoft Computer Vision APIs.
MIT License
11 stars 8 forks source link

Does not support all regions #5

Closed mrmax99 closed 6 years ago

mrmax99 commented 6 years ago

There is a restriction in utility.js: if (_opt["request-origin"] && !config["origin"].includes(_opt["request-origin"])) { var _err3 = new Error("Specified request origin is not valid"); This prevents the API from being used if the origin is not within the config list (in config.json) which only includes: ["westus", "eastus2", "westcentralus", "westeurope", "southeastasia"],

This does not include all the other azure locations: https://azure.microsoft.com/en-us/global-infrastructure/locations/

If you end up with a location outside the built-in list, then it blocks the API call from working. I ended up with one outside this list and hit the error.

viane commented 6 years ago

Thanks for let me know, when I wrote this it was only 3 regions that were supported. Will work on update the region tonight. Just carious what region were you passing?

mrmax99 commented 6 years ago

I needed southcentralus

viane commented 6 years ago

Cool, so I did little research on the Azure API support for CV, here is the link of Supported Regions of all APIs, the CV is under AI+Machine Learning (The 1st product) and there is also another page saying that you can get your subscription key that only valid to These Regions (Which the list is unchanged).

So after I gave a try, used the subscription key that based on my LinkedIn account, even though the southcentralus suppose to be supported but I'm not able to make it work, the API calls failed due to access denied of using the invalid API key. Therefore I want to ask a favor from you to use your key to call the API to south central and see if that the region is actually accessible, if it is then I will add the all other newly supported regions to the library and we also might just write a note to MS to tell them to update the API doc.

Here is the curl command you just paste and run to see if you key works in south central us: curl -H "Ocp-Apim-Subscription-Key: <your-subscription-key>" -H "Content-Type: application/json" "https://southcentralus.api.cognitive.microsoft.com/vision/v2.0/analyze?visualFeatures=Categories,Description&details=Landmarks&language=en" -d "{\"url\":\"http://upload.wikimedia.org/wikipedia/commons/3/3c/Shaki_waterfall.jpg\"}"

mrmax99 commented 6 years ago

That's interesting that the list of regions on your second link doesn't include southcentralus, though it maybe hasn't been updated in over a year based on the date? The first link has southcentralus listed as supported by computer vision, so that's consistent at least.

When you tried your call in southcentralus, did you get a new API key in southcentralus or use a different location? I think the computer vision API keys are only for specific regions.

I made this commit on a fork (just added southcentralus) to test it out (and unblock my own development) and things are working perfectly now for me: https://github.com/mrmax99/microsoft-computer-vision/commit/f60b5e9e41bcf8f58c45216902d7671af7e6fa89

By the way, your curl command above appears to be using v2.0 while you're project is using v1.0? config.json: "request-base-URL": "https://{origin}.api.cognitive.microsoft.com/vision/v1.0",

viane commented 6 years ago

Indeed, and always feel free to make a PR, I appreciate that. Also, the first link I listed is the doc I saw when I wrote the package, the second link was added later, same apply to the API version. MS made little confusing of the way you can get an API key, you get different region availability based on where you create the account... My account was not created via Azure and I think that's why it won't have access to the newer regions. I will update the package tonight to make the following changes:

  1. Update API url version
  2. Get an account that has access to new regions and add testcase, once the testcase passes I will push the update.

So, expect the update on tomorrow some point, should no later than noon.

mrmax99 commented 6 years ago

I am not sure of the differences between v1.0 and v2.0, but my Azure API instance indicates that I should be using v1.0. I am not sure if v2.0 will work with my API or not, and I just created it last week, so I would be cautious with upgrading the API version in the url. Perhaps at least a switch should be available to select it if you want to support both?

viane commented 6 years ago

I have tested with version 2.0 and it looks like the version was backward compatible link #6

viane commented 6 years ago

The updates are now merged into master, let me know if there are more issues.