How to automatically disable Azure Maps api key when reaching close to free tier limit

Eugen Mihaescu 20 Reputation points
2025-07-19T09:57:25.1433333+00:00

Hello everyone!

I'm trying my best to properly implement Azure Maps in my Winui3 C# App, my main usage is simply to scroll around and view my surroundings on the map in satellite view and normal view, i see there are some limitations for the free tier, namely:

Base Map Tiles 5,000
Base Map Tiles 5,000
Imagery Tiles​ 1,000
Traffic Tiles​​ 5,000
Weather Tiles​​ 1,000
Map provisioning 1 resource unit per hour
Map provisioning 1 resource unit per hour
Map render 1K transactions
Feature state 1K transactions
Web feature 1K transactions

These limitations at first seem incredibly small and trigger happy on everyone credit card, so to prevent leaving the free tier i would like to know how could i activate a limit of usage, let say i would like to completely deactivate the maps api key as soon as i reach 4000 base map tiles usage for example, a competitor (i will not name it here) has all of these things implemented in the form of "quotas", as in, you define when should the service stop after x ammount of usage, therefor making it completely safe to keep yourself in the free tier if that is your wish.

How could i do something similar in Azure Maps, i really can not afford leaving the free tier.

Thank you all for your help!

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
{count} votes

Accepted answer
  1. Manas Mohanty 8,150 Reputation points Microsoft External Staff Moderator
    2025-07-24T07:21:17.24+00:00

    Hi Eugen Mihaescu

    We can trigger a runbook automation or python function as action once log analytic workspace receives 429 rate limits.

    How to configure custom metric alert and run actions

    Runbook automation script or python functions can do below to serve the purpose

    1. can remove the roles of assigned user from Azure Map resource
    2. We can also expire or remove the SAS token which might act as authentication for users
    3. We can also remove the key vault secret user role on a keyvault secret which contains the Azure Map key for authentication.

    Runbook automation in python 3

    Please let us know if this approach would work for you

    Thank you.


3 additional answers

Sort by: Most helpful
  1. rbrundritt 21,191 Reputation points Microsoft Employee Moderator
    2025-07-21T15:49:23.9733333+00:00

    I'm not aware of any way to set limits on individual API's easily however you could start by setting up an Azure budget on the Azure Maps resource and set it to zero (or some very low number). I believe you can use roles to limit which API groups an Azure Maps account can access. In theory (I haven't tried) you could have multiple Azure Maps accounts, one for each API group you need access to, and then use multiple accounts with your app. It would be a bit messy to maintain. I would start just with a budget and see how that works for you.

    1 person found this answer helpful.

  2. Suwarna S Kale 3,946 Reputation points
    2025-07-19T13:25:15.6433333+00:00

    Hello Eugen Mihaescu,

    Thank you for posting your question in the Microsoft Q&A forum. 

    Since Azure Maps doesn't natively provide quota management like some competitors, you'll need to build a client-side solution to monitor and control usage. Here's a comprehensive approach you may try: 

    1. Client-Side Request Tracking 

    • Implement counters for each API call type in your WinUI3 app 
    • Store daily counts in local storage (ApplicationData.LocalSettings) 
    • Reset counters at midnight using a background task 

    2. Usage Throttling Logic - This component tracks API consumption in real-time and enforces soft limits before hitting Azure's free-tier ceilings. The dictionary _usageCounters maintains daily tallies for each service (map tiles, imagery, etc.). The CanMakeRequest() method checks if a call would exceed your predefined safety buffer (e.g., 4,000 tiles instead of Azure’s 5,000 limit). It auto-resets counts at midnight to align with Azure’s daily quota cycle. 

    3. Request Interception Layer - This wrapper acts as a gatekeeper for all Azure Maps API calls. Before executing a request (e.g., fetching a tile), it: 

    1. Checks quota availability via CanMakeRequest()
    2. Blocks requests that would breach limits, showing a user warning. 
    3. Increments counters only after successful calls.  By centralizing all API access through this layer, you ensure consistent enforcement across your app. 

    4. Visual Feedback System 

    • Add a usage meter in your UI showing remaining quota 
    • Implement progressive warnings (80%, 90%, 100%) 
    • At 100%, gray out the map and show explanation 

    5. Caching Optimization 

    • Implement tile caching (MemoryCache + local file storage) 
    • Set Cache-Control headers for maximum reuse 
    • Prioritize cached tiles when near quota limits 

    6. Fallback Behavior when quotas are reached: 

    • Switch to static map snapshots 
    • Disable non-essential layers 
    • Provide "Try again tomorrow" messaging 

    7. Emergency Kill Switch 

    • Maintain a secondary "disabled" API key 
    • Automatically rotate to disabled key when thresholds met 
    • Implement manual override for testing 

    Some Key Considerations: 

    1. Client-side tracking isn't foolproof (users can clear storage) 
    2. Combine with Azure Functions for more reliable server-side tracking 
    3. Monitor actual usage in Azure Portal weekly to validate your client counts 
    4. Consider implementing a "Lite Mode" that reduces tile requests 

    This approach gives you quota-like control while staying within Azure Maps' existing architecture. For more robust enforcement, you'd need to add a proxy service that tracks usage server-side before forwarding requests to Azure Maps. 

    If the above answer helped, please do not forget to "Accept Answer" as this may help other community members to refer the info if facing a similar issue. Your contribution to the Microsoft Q&A community is highly appreciated. 


  3. IoTGirl 3,716 Reputation points Microsoft Employee Moderator
    2025-07-20T19:39:46.2966667+00:00

    Hi @Eugen Mihaescu

    Does my answer to a previous post on this subject help you? https://learn.microsoft.com/en-us/answers/questions/2129749/best-practice-to-monitor-azure-maps-transactions

    You have the limits you want to set as published so you can do so using the built-in Azure alerting and monitoring tools as you would with any other Azure offering.

    Sincerely,

    IoTGirl


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.