Monitoring google maps API costs and requests

Hi Everyone,

I’ve just seen that my google maps API requests are going through the roof compared to my Bubble app usage and I would like to know why.

In my google cloud console I see that I am using roughly 1000 requests per day, but it seems crazy to me compared to my users activity !

Today, I had roughly 65 visits my one page single app where 2 google maps are displayed, and it triggered 300 google maps requests.

How can I monitor, and know, when API requests are sent ?

Is there a way to control requests number for each user ?

Thank you for you help
Thibaut

Is that really a lot? If each of the maps make one request then that’s already 130 requests on page load from the 65 visits. Are users performing additional searches/interacting with the map or is it meant to show a static location? And did you restrict your API keys to your domain?

Hi, were you able to get this sorted? I just received an absolutely enormous bill from Google for the maps / geocode api, and have no clue why. I dont have any maps displayed on my app, so I’m thinking its something related to extracting a country from a text address, but I have no idea why I suddenly went from $0 in previous months to this huge bill this month.

You said it was 0 on previous months, did you have Google cloud console credits by chance? (Usually $300-500 credit they issue)

Do you have security on your Google keys?

Have you confirmed it’s from your site and not a bad actor using your keys?

I will say we moved away from Google maps as our map display on a client site due to 60k visitors per month (1 map load per page load) resulted in a $500/mo bill with Google so it can get quite expensive.

Thanks Chris.

Looks like a few issues here - on the billing tab of the google platform, it shows my march invoice as $34.35 and a note “includes CA$0.00 in credits , CA$0.00 tax”. The actual invoice itself for March shows an invoice amount of $0, and there was no charges run through PayPal. Roughly the same $ amount as the month prior with same notes (as shown on the billing tab). Also a $0 invoice. About the same for Jan etc.

The invoice for April is at ~$1700. It looks like the costs started racking up one day in early April, so I’m wondering if there’s something I changed on my app that opened the floodgates on billing or…? I’m thinking I’m not fully understanding when the api gets called. My site is basically a job board, so it is not complex. I don’t display maps but I do have location fields where a corporate address (city, country) can be entered, as well as the location for a job posting (city, country). The corporate profile shows the company’s location, and the job posting detail page shows the job location. Users can search for jobs by country as well. Aside from that, I can’t think of anything else that would rely on location data.

Google is showing a usage amount of almost 320,000 requests. That seems to line up with the pricing I was seeing at around $5/1000 requests to cause an invoice amount of ~$1,700. But the website is only getting a few dozen visitors a day, and maybe two or three dozen jobs posted a day, so something is out of whack.

As far as I can tell, security on the keys should be OK. The HTTP referrers are limited to my domain. I dont have any custom API calls to the geocode api. I could be missing something within bubble in terms of my key being unintentionally exposed but I dont know how / where that would be happening.

Last thing is that I had budget notifications set with Google at $250, and lower threshold notifications at $125 etc (50% of budget). I received the exceedance notification after I was notified by PayPal that I had been invoiced by Google, and didnt receive the lower threshold exceedance notification at all (i.e. should have gotten an email when costs >$125 in early april, then an exceedance notification after the first week of april when the costs were >$250).

Not sure what’s happening here but I have to basically shut down some location-based functions on the site until this gets sorted. :frowning:

in case anyone comes back to this in the future, i had used the :extract function to pull city & country information from a location field, then displayed the city & country in a repeating group. Each cell in the repeating group used two api calls, with about 500 to 600 records in the repeating group (i.e. 1,000 to 1,200 api calls upon loading the repeating group, every time the rg is loaded). I didnt realize the :extract function relied on an API call to the Geocode API, so my API requests went through the roof when I got a very small amount of traffic. :grimacing:

2 Likes

adding a bit more to this since I’m not really seeing any documentation with bubble or elsewhere explicitly saying this in black and white:

  • using the :extract function on a geographical address will incur an API request via geocode.
  • if you simply display a geographical address on your site, without using :extract or anything else, it requires an API call via geocode.
  • if you have a repeating group that displays geographical addresses, and / or uses :extract to pull some info out of a geographical address, your API request volume will go through the roof. every time the page is loaded, your site will incur individual API requests for every instance the field is displayed in your repeating group. if the page is reloaded, the API requests will be incurred again.
  • you can set a daily request volume limit, a limit on requests per minute, and a limit on requests per minute per user in the Google Cloud Platform (search for ‘quotas’ at the top search bar and you can likely figure it out from there).
  • in my use-case (a job board), I wanted to allow users to type in their corporation location, and the location for a job opening. To make the entries consistent, I was using the geocode API to extract the city and country from whatever the user inputted, in order to prevent getting similar entries like U.S., USA, United States etc. I now only use the :extract function to pull the city and country, then i save those values as text, then display the text throughout the site as needed. i still need some API requests to make this happen, but after going through and removing all the reliance on geographical addresses and :extract throughout the site, I’ve reduced my API calls by ~99%.

This one seems much more clear in hindsight, but I can see how others may accidentally stumble into this scenario as well, so I hope this helps.
-Ben

3 Likes

Thanks everyone for your inputs

@bennymac1 are you sure the “:extract” function requires an API call ? Looking at google chrome dev tools there is nothing showing up when I am using :extract

Here is what Bubble’s chat bot says about it :

The :extract function itself does not send API requests to Google Maps. However, when dealing with geographic addresses in Bubble, if you need to manipulate or process the address data, such as converting it into a latitude and longitude, Bubble will use the Google Maps API to encode it. For example, when you have a geographic address and you want to extract specific components of it, such as the street number or the postal code, the :extract function allows you to do this without making additional API requests to Google Maps.

I’ll be the first to admit I could be wrong on this one, since I feel like I’m trying to reverse engineer the google charges in the dark. I can’t find anything in writing that says the :extract function explicitly uses an API call or it doesnt. But that is the only thing I can come up with that was racking up the geocode API calls (:extract getting used in a repeating group, and displaying geographic addresses instead of text). After I stopped this approach and revised to only show text in my repeating groups (and elsewhere on the site), my geocode API calls dropped >99%. I’m only incurring between 2 to 5 dozen API requests per day, depending on how many jobs are posted per day, how many corporate profiles are created etc vs a previous high of almost 31,000 on one day.

Sorry, meant to add as well - I did a little debrief and shared it in Greg’s buildcamp community, but you can see in this loom vid a bit more detail as to what I had set up and how the API request volume got so high: Preliminary Findings | Loom