Will I be charged twice when using rewrites?

I have two separate serverless projects on Vercel: a 100% client-side rendered frontend and an API. Due to different domains, I’m experiencing CORS preflight requests that i would like to avoid, and I also don’t want to expose my API’s address to the frontend users.

I’m planning to use Vercel’s rewrite feature to route API requests through my frontend domain. My main concern is billing: Will I be charged twice for bandwidth and execution time when using this rewrite configuration?

It wasn’t very clear to me if the rewrite would increase bandwidth costs. Can the middleware identify that both projects are within Vercel’s infrastructure and waive this cost? Another question, are middleware billings per execution or by time? Is the time counted the full request time or only the rewrite execution time?

2 Likes

Same question here. Also does API rewrites feature something related to the fast edge routing layer infra that vercel has?

Hi @giulianopenido, welcome to the Vercel Community!

When using rewrites to proxy requests between your Vercel projects, you will be charged for both the middleware execution and the destination function invocation, but the bandwidth costs work differently than you might expect.

Here’s the breakdown:

Bandwidth: You’ll be charged for the bandwidth from your frontend to the client, but not for the internal traffic between your Vercel projects. Vercel doesn’t charge for bandwidth between projects within their infrastructure.

Function Invocations: You’ll be charged for both:

  • The middleware function that handles the rewrite
  • The API function that processes the actual request

Middleware Billing: Middleware is billed per execution, not by time. Each time a request triggers your middleware (including the rewrite), it counts as one invocation. The execution time for billing purposes is only the time your middleware code actually runs, not the full request duration.

So yes, you’ll have two function invocations per API request (middleware + API function), but you won’t pay double bandwidth costs since the internal routing between Vercel projects doesn’t incur additional bandwidth charges.

Resources: