Go to main content

Using Kentico Cloud Asset library can cost you

Surprise, surprise. I obtained an email subjected Kentico Cloud overusage notification. That is something you don't want to see after the first month of running a small website on Kentico Cloud. And, if you cache HTML output server-side, it is even more strange. In this article, I will give you a friendly warning that every single image request is considered as a paid Content API call and provide you with a tip how to handle that.

Using Kentico Cloud Asset library can cost you

The situation

My beautiful wife writes a blog that is quite popular here in the Czech Republic. It was using Kentico CMS for a long time. For her, it was painful to write posts there. Despite the fact that she was formatting articles in the Portal Engine WYSIWYG, she had to deal with HTML code a lot to avoid any unwanted styling.
Recently, we redesigned the blog to adjust it to her current business needs, and we addressed underlying technology as well. We moved from Kentico CMS to Kentico Cloud to improve her writing experience.
As the blog is almost a non-profit project, we wanted to cut down any unnecessary expenses. In case of using Kentico Cloud, we wanted to keep the number of Content API calls as lowest as possible.

What is a Content API call?

The Kentico Cloud Pricing page states: "A content API call represents a single request for fetching content (Delivery API) or a single modification request (Content Management API). Content API calls also include requests for assets, such as images, videos, or uploaded documents." That is pretty clear, right? However, I haven't read that carefully before implementing the new website.

The problem

I implemented the new website with HTML output caching and believed that this would lower down API usage to almost zero. I was terribly wrong.

The blog is about baking, and each page renders multiple images. As those images are stored in the Kentico Cloud Asset library and requested from there, no matter the caching, URLs in <img> tags get loaded every time the page is visited. Ouch.

Technically, requesting an URL staring with https://assets.kenticocloud.com will cost you a Content API call.
Imagine how many image requests are made on the blog posts list page. And multiply it by 450-page visits every day. At the end of the month, it was nearly 300.000 Content API calls.

Kentico Cloud Free plan includes 50.000 Content API calls for free which is excellent. And every 1.000 extra is for $0.10. In that situation, the final price would be $25/month.
The price is not high at all in comparison to what an excellent service you get by using Kentico Cloud. My point is that this could be kind of surprise.

The solution

That was a challenge for me because saving $25 every month means couple more beers.
Instead of caching the HTML output, I implemented a solution that:

  • caches Delivery API responses,
  • iterates Asset elements and transforms them into Base64 strings,
  • parses Rich text elements and transforms referenced images into Base64 strings as well.

That has significantly lowered the number of Content API calls because all the content including images is cached server-side now.

When I was researching the issue, I came across a forum thread discussing exactly the same problem. The solution suggested in there is to use Kentico Cloud Webhooks to duplicate assets in another service like Azure CDN. This could be a fine solution as well. However, that would involve another service in the dev stack and possibly bring more issues. Moreover, server-side caching seems to be much simpler and elegant solution in my case. 

Node.js goodies

In case you got here, and you are okay with using Node.js, I have a reward for you. I implemented an unofficial Delivery SDK for Node.js that handles caching the same way I describe in the section above. The SDK is available on Github or as an NPM package. Regarding the caching feature, you will be interested in the getContent method. Cheers!

Milan Lund

is a freelance web developer and a proud Basenji owner. His specialties are Kentico CMS/EMS and Kentico Cloud.

Further reading

all posts
  • Kentico Cloud

    An online tool for developers who use Kentico Cloud: Request Delivery

    In this article I would like to present an online tool for developers who use Kentico Cloud. The tool helps them overview obtained content in JSON format.

  • Kentico CMS & EMS

    Kentico macro repeater

    Over the years, the macro engine in Kentico has become a mighty tool that serves you data from all corners of the CMS. What I love the most is that they don't limit much where you …

  • Kentico Cloud

    Migrate Kentico CMS pages data to Kentico Cloud

    In this article, you'll learn what it takes to migrate your pages data from Kentico CMS to Kentico Cloud using the Migration tool.