networkingcost-optimizationapifinops

API payload size and cost: what every extra kilobyte is worth

An API response is billed by the byte once it leaves the cloud. Multiply a few hundred wasted bytes by a billion calls and the padding becomes a real line item. Here is how to price a payload.

The C3X Team··7 min read

Quick answer

At the standard AWS internet egress rate of 0.09 dollars per GB, one kilobyte of API response costs about 0.000000086 dollars. That sounds trivial until you multiply: one billion calls per month with a 5 KB response transfers roughly 4.66 TB and costs about 430 dollars in egress alone. Trimming that response to 2 KB saves about 258 dollars per month, and gzip on a typical JSON body cuts 70 to 80 percent more. The rule of thumb is that every kilobyte of response costs roughly 86 dollars per billion calls, so payload discipline is a cost control, not just a latency one.

Most teams size their API by latency and by CPU. Very few size it by bytes on the wire, which is odd, because bytes on the wire are the part the cloud bills directly. A response body is charged as egress the moment it crosses from your region to the internet, and unlike compute there is no way to amortize it with a reservation or a savings plan. The meter is linear and unforgiving.

The unit economics of a kilobyte

Start with the base number. AWS charges 0.09 dollars per GB for the first 10 TB of internet egress in US regions. One GB is 1,048,576 KB, so a single kilobyte costs about 0.0000000858 dollars. Multiply by a billion and you get roughly 86 dollars. That is the number worth memorizing: each kilobyte of response body costs about 86 dollars per billion calls per month.

Response size1M calls/mo100M calls/mo1B calls/mo
1 KB0.09 USD8.58 USD86 USD
5 KB0.43 USD43 USD429 USD
20 KB1.72 USD172 USD1,717 USD
100 KB8.58 USD858 USD8,583 USD

At a million calls a month nothing here matters. At a billion, the difference between a lean 2 KB response and a lazy 20 KB one is about 1,550 dollars every month, which is a full-time engineer's cloud budget spent on whitespace and unused fields.

Where the bloat comes from

The recurring offenders are predictable. Serializing an entire database row when the client needs four fields. Returning nested objects the caller discards. Pretty-printed JSON with two-space indentation, which can add 10 to 20 percent to a deeply nested document for zero benefit in a machine-to-machine call. ISO timestamps with microsecond precision and timezone offsets where a Unix integer would do. Null fields serialized explicitly. Base64-encoded binary inline, which inflates by 33 percent before any other consideration. And the biggest one: unbounded list endpoints that return every record because nobody implemented pagination.

Compression changes the arithmetic

JSON compresses extremely well because it is repetitive by nature. Gzip typically reduces a JSON body by 70 to 85 percent, and Brotli at a moderate quality level gets another 10 to 15 percent beyond gzip on text. A 20 KB response that compresses to 3 KB drops the billion-call cost from about 1,717 dollars to about 258 dollars. The CPU cost of compressing is real but small: gzip at level 6 on a 20 KB body takes well under a millisecond on a modern core, which on a 0.0432 dollars per hour m7g.large works out to a rounding error against the transfer saved. The trade-off is analyzed in compression to reduce cloud cost.

Headers count too

A response body is not the whole payload. HTTP headers travel on every response, and verbose CORS headers, long cache-control directives, tracing headers, and oversized cookies can add 500 bytes to 2 KB per response. For a chatty API making many small calls, headers can exceed the body. A 200-byte JSON response with 1.5 KB of headers is spending 88 percent of its bytes on metadata. HTTP/2 header compression helps between the client and the edge, but if your origin is behind a load balancer that re-expands headers, the internal hop pays full price.

The hidden multipliers

Payload cost rarely stops at one hop. A response that travels from a service in one availability zone to an API gateway in another pays 0.01 dollars per GB each way before it ever reaches the internet. If a request fans out to five internal services and each returns a full object that the aggregator trims, you pay cross-zone charges on the untrimmed version five times. This is the pattern described in chatty microservices network cost. Trimming at the source, not at the edge, compounds the saving across every internal hop.

A practical payload budget

Give each endpoint a byte budget the way you would give it a latency budget. A reasonable starting point: list endpoints capped at 100 items with a hard page size, detail endpoints under 4 KB uncompressed, compression mandatory above 1 KB, no pretty-printing outside development, null fields omitted, and binary served as a signed URL to object storage rather than inlined. Measure the p50 and p99 response size in your metrics alongside latency. Once the number is visible in a dashboard, it stops growing quietly.

Price it before it ships

The reason payload bloat survives so long is that nobody sees the bill attributed to it. The egress line says only that you moved 4.66 TB, not that 60 percent of it was unused fields. Estimating traffic volume for a new endpoint during design, against real per-GB rates, makes the trade-off concrete while the schema is still easy to change. Price your API infrastructure against the resource catalog before the schema is frozen.

FAQ

How much does a kilobyte of API response cost?

At the AWS internet egress rate of 0.09 dollars per GB in US regions, one kilobyte costs about 0.0000000858 dollars. The useful form of that number is roughly 86 dollars per kilobyte per billion calls per month. A 5 KB response served a billion times costs about 429 dollars in egress, while a 20 KB response costs about 1,717 dollars for the same call volume.

Does compression actually reduce API cost?

Substantially. JSON is highly repetitive and typically compresses 70 to 85 percent with gzip, with Brotli adding another 10 to 15 percent on text. A 20 KB response compressing to 3 KB drops the billion-call egress cost from about 1,717 dollars to about 258 dollars. The CPU cost is negligible: gzip level 6 on a 20 KB body takes well under a millisecond on a modern core.

What makes API payloads larger than they need to be?

Serializing full database rows when the client needs a few fields, returning nested objects the caller discards, pretty-printed JSON in machine-to-machine calls, high-precision timestamps where integers suffice, explicitly serialized null fields, inline base64 binary which inflates 33 percent, and unbounded list endpoints without pagination. The last one is usually the largest single contributor.

Do HTTP headers add meaningful cost?

For chatty APIs with small bodies, yes. Verbose CORS headers, long cache-control directives, tracing headers, and oversized cookies can add 500 bytes to 2 KB per response. A 200-byte JSON body with 1.5 KB of headers spends 88 percent of its bytes on metadata. HTTP/2 header compression helps client-side but internal hops behind a load balancer may pay full price.

Does payload size affect internal traffic cost too?

Yes, and it compounds. A response crossing availability zones is charged 0.01 dollars per GB in each direction before it reaches the internet. If a request fans out to five internal services that each return full objects an aggregator then trims, you pay cross-zone charges on the untrimmed version five times. Trimming at the source saves on every hop rather than only the last one.

How does C3X help with API payload cost?

C3X prices infrastructure from Terraform before deployment, including the load balancers, gateways, and cross-zone paths that API traffic crosses. Seeing the priced topology at design time makes the per-GB rate on each hop visible, which is what turns an abstract payload-size decision into a concrete monthly number while the schema and the architecture are still easy to change.

What to do next

Know what your traffic costs before it ships. C3X prices your Terraform against a live resource catalog. Start with the quickstart.

Try C3X on your own Terraform

Free and open source. No API key required. One command to install, one command to estimate.