Amazon API Gateway is the Amazon Web Services(AWS) solution for connecting an API to the public Internet or a private network. In a lot of cases, it’s an important piece of AWS architecture and it’s therefore equally important to understand its pricing. API Gateway is often also the most expensive piece of AWS serverless infrastructure, though depending on how it is used and optimized, costs can be kept very low.
In this blog post, we will cover AWS’s API Gateway pricing, the free tier, and how to optimize its costs.
API Gateway provides a free tier that is available for 12 months after the initial sign-up date. When this 12-month term expires or if your application use exceeds the tiers, you simply pay standard rates.
HTTP APIs are charged based on the number of API calls made. HTTP APIs calls are metered in 512 KB increments, so for example, 513 KB is metered as two requests.
This is the pricing in the Europe (Ireland) region:

REST APIs are also charged based on the number of API calls made. This is the current pricing in the Europe (Ireland) region.

Websocket APIs are charged based on the number of messages sent and received as well as the total number of connection minutes. Messages are metered in 32 KB increments, so for example, 33 KB is metered as two requests.
The table below shows the current pricing for messages in Europe (Ireland):

Connection Minutes are charged at $0.25 per million connection minutes.
REST APIs provide the ability to provision a dedicated cache to improve performance. The pricing for the cache is based on the amount of memory provisioned.

There might also be other additional charges depending on how the API Gateway is being used such as:
The costs of Amazon API Gateway are often higher than of a Lambda itself and while these costs are adequate for the specific features (e.g. authentication management, caching, request/response transformation, proxying), there are a couple of ways to generally save on its costs or even not use it at all and choose other services from AWS.

What you can do to optimize your API Gateway costs is to choose the right type of API Gateway. AWS offers both REST APIs and HTTP APIs. The HTTP API has more limited functionality but is also much cheaper. If it suits your needs you can save a lot of money by using it over the REST API.
For existing REST APIs, consider migrating to HTTP APIs. When planning for migration, see Choosing between HTTP APIs and REST APIs to compare HTTP API and REST API supported features.
Another great tip to save on your API Gateway bill is to use AWS service proxy integrations instead of combining a Lambda function to transfer/transform input data from the client. You can integrate API Gateway with other AWS services directly (e.g. Kinesis, DynamoDB, SQS, SNS, etc.) by using API Gateway integration features.
When your front-end is the only consumer of the backend APIs, you can leverage Cognito to obtain IAM credentials for your users. They can then invoke your Lambda functions safely using the AWS Javascript SDK and the temporary credentials. This solution allows you to achieve both authentication and authorization via IAM, avoiding the need for an API Gateway at the cost of reduced functionalities (you have to prepare your request on the frontend side, and also manage responses and errors in your Lambda code).
As your application scales, consider replacing the API Gateway with an ALB (Application Load Balancer). Since ALB supports triggering the Lambda function, ALB could be a better choice for cost savings unless you’re using Amazon API Gateway’s unique features, such as authentication management, caching, and request/response transformation.
Remove any unnecessary API calls and optimize your application to prevent them. As your application evolves we often end up with redundant and unnecessary API calls and these can add significantly to our costs.
If you transfer data from API Gateway to the public Internet, you will be charged at the standard data transfer rate (0.09$ per GB).

At StormIT we have helped many customers to optimize their overall spending on data transfer (egress bandwidth) from different industries with a broad range of use cases from web applications and blogs to media streaming and gaming.
Using a content delivery network such as Amazon CloudFront is essential to keeping data transfer costs low. CloudFront moves your most accessed content to the “front” of the AWS network (i.e., PoPs), ensuring fast delivery to your end users. Data transfers into CloudFront from other AWS resources (S3, EC2, API Gateway) are free.

Obviously, every project/case is unique, but we are confident that by smartly using CloudFront it is possible to achieve overall lower costs and improved performance.
Amazon API Gateway is one of the most popular serverless services from AWS. Customers are charged based on a pay-as-you-go model which is very cost efficient for some customers. This blog post introduced Amazon API Gateway pricing and should help you with the cost optimization of this service.
An AWS Solutions Architect with over 5 years of experience in designing, assessing, and optimizing AWS cloud architectures. At Stormit, he supports customers across the full cloud lifecycle — from pre-sales consulting and solution design to AWS funding programs such as AWS Activate, Proof of Concept (PoC), and the Migration Acceleration Program (MAP).