---
name: vercel-cost-tuning
description: 'Optimize Vercel costs through plan selection, function efficiency, and usage monitoring.

  Use when analyzing Vercel billing, reducing function execution costs,

  or implementing spend management and budget alerts.

  Trigger with phrases like "vercel cost", "vercel billing",

  "reduce vercel costs", "vercel pricing", "vercel expensive", "vercel budget".'
allowed-tools: Read, Write, Edit, Bash(vercel:*), Bash(curl:*), Grep
version: 1.18.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - vercel
  - cost-optimization
  - billing
  - monitoring
compatibility: Designed for Claude Code
title: vercel-cost-tuning
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/vercel-cost-tuning
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/cost-estimation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/vercel-cost-tuning/references/cost-estimation.md), [references/cost-reduction-strategies.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/vercel-cost-tuning/references/cost-reduction-strategies.md), [references/errors.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/vercel-cost-tuning/references/errors.md), [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/vercel-cost-tuning/references/examples.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/vercel-cost-tuning`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/vercel-cost-tuning`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/vercel-cost-tuning) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/vercel-cost-tuning`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/vercel-cost-tuning --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/vercel-cost-tuning --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Vercel Cost Tuning

## Overview

Optimize Vercel costs by understanding the Fluid Compute pricing model, reducing function execution time, leveraging edge caching to avoid function invocations, and configuring spend management. Covers plan comparison, cost drivers, and monitoring.

## Prerequisites

- Access to Vercel billing dashboard
- Understanding of current deployment architecture
- Access to Vercel Analytics for usage patterns

## Instructions

### Step 1: Understand the Pricing Model

Vercel uses **Fluid Compute** pricing (for new projects):

| Resource | Hobby (Free) | Pro ($20/member/mo) | Enterprise |
|----------|-------------|---------------------|------------|
| Bandwidth | 100 GB | 1 TB included | Custom |
| Serverless Execution | 100 GB-hrs | 1000 GB-hrs included | Custom |
| Edge Function invocations | 500K | 1M included | Custom |
| Edge Middleware invocations | 1M | 1M included | Custom |
| Image Optimizations | 1000 | 5000 included | Custom |
| Builds per day | 6000 | 6000 | Custom |
| Concurrent builds | 1 | 1 (more available) | Custom |

**Fluid Compute billing breakdown:**

- **Active CPU time**: charged per ms of actual CPU usage
- **Provisioned memory**: charged per GB-second of allocated memory
- Benefit: you pay for actual work, not idle waiting (e.g., waiting for a database response)

### Step 2: Identify Cost Drivers

```bash
# Check usage via API
curl -s -H "Authorization: Bearer $VERCEL_TOKEN" \
  "https://api.vercel.com/v2/usage" | jq .

# Top cost drivers on Vercel:
# 1. Serverless function execution time (CPU + memory)
# 2. Bandwidth (large responses, unoptimized images)
# 3. Edge Middleware invocations (runs on EVERY request)
# 4. Image optimizations (each unique transform costs)
# 5. Build minutes (frequent deploys or slow builds)
```

### Step 3: Reduce Function Execution Costs

```typescript
// 1. Right-size function memory — don't over-allocate
// vercel.json
{
  "functions": {
    "api/lightweight.ts": { "memory": 128 },    // Simple JSON responses
    "api/standard.ts": { "memory": 512 },       // Database queries
    "api/heavy.ts": { "memory": 1024 }          // Image processing
  }
}

// 2. Move read-only endpoints to Edge Functions (cheaper, no cold starts)
// api/config.ts
export const config = { runtime: 'edge' };
export default function handler() {
  return Response.json({ features: ['a', 'b'] });
}

// 3. Cache function responses at the edge
// Eliminates function invocations entirely for cached routes
export default function handler(req, res) {
  res.setHeader('Cache-Control', 's-maxage=3600, stale-while-revalidate=86400');
  res.json(data);
}
```

### Step 4: Reduce Bandwidth Costs

```json
// vercel.json — compress and cache aggressively
{
  "headers": [
    {
      "source": "/static/(.*)",
      "headers": [
        { "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }
      ]
    }
  ],
  "images": {
    "sizes": [640, 750, 1080],
    "formats": ["image/avif", "image/webp"],
    "minimumCacheTTL": 86400
  }
}
```

Key bandwidth reducers:

- Use Vercel's image optimization (auto WebP/AVIF conversion)
- Set aggressive cache headers on static assets
- Use ISR to serve static HTML instead of SSR
- Compress API responses (Vercel auto-compresses with Brotli)

### Step 5: Optimize Middleware Costs

Middleware runs on **every matched request**. Minimize its scope:

```typescript
// middleware.ts — scope to specific paths only
export const config = {
  matcher: [
    // Only run middleware on API routes and protected pages
    '/api/:path*',
    '/dashboard/:path*',
    // Skip static files, images, and public assets
    '/((?!_next/static|_next/image|favicon.ico|public).*)',
  ],
};

export function middleware(request) {
  // Keep logic minimal — this runs on every matched request
  // Avoid: database queries, external API calls, heavy computation
  // Good: cookie checks, header modifications, redirects
}
```

### Step 6: Configure Spend Management

In the Vercel dashboard under **Settings > Billing > Spend Management**:

```
Default budget: $200/month on-demand usage
Options:
- Set custom budget limit
- Enable hard limit (pauses all projects when reached)
- Configure email alerts at 50%, 75%, 90%, 100%
```

```bash
# Check current usage against budget via API
curl -s -H "Authorization: Bearer $VERCEL_TOKEN" \
  "https://api.vercel.com/v2/usage?teamId=team_xxx" \
  | jq '{period: .period, bandwidth: .bandwidth, execution: .serverlessFunctionExecution}'
```

## Cost Optimization Checklist

| Action | Impact | Effort |
|--------|--------|--------|
| Add `s-maxage` cache headers | High — eliminates function invocations | Low |
| Use Edge Functions for simple endpoints | Medium — cheaper than serverless | Low |
| Right-size function memory | Medium — reduces GB-hr cost | Low |
| Scope middleware matcher | Medium — reduces edge invocations | Low |
| Enable image optimization | Medium — reduces bandwidth | Low |
| Use ISR instead of SSR | High — serves cached HTML | Medium |
| Optimize build speed | Low — reduces build minutes | Medium |
| Set spend management alerts | Safety — prevents surprise bills | Low |

## Output

- Function memory right-sized per endpoint
- Edge caching reducing function invocations
- Middleware scoped to minimize invocations
- Spend management configured with budget alerts
- Usage monitoring via API

## Error Handling

| Error | Cause | Solution |
|-------|-------|----------|
| Unexpected bill spike | Uncached high-traffic endpoint | Add `s-maxage` to the response |
| Projects paused | Hard spending limit reached | Increase limit or optimize usage |
| Image optimization quota exceeded | Too many unique image transforms | Reduce `sizes` array, increase cache TTL |
| Build minutes exceeded | Slow builds or too many deploys | Use `ignoreCommand` to skip non-code changes |

## Examples

### Reduce an invocation spike with a measurable rollback

For a high-traffic read endpoint, add a conservative `s-maxage` response policy in a preview deployment and compare invocation count, cache hit rate, and response correctness against the prior release using synthetic requests. Set spend alerts before rollout and avoid a hard account-wide pause unless the owner accepts its blast radius. If personalized content is accidentally cached, immediately roll back the header change, purge only the affected deployment cache where supported, and document the regression.

## Resources

- [Vercel Pricing](https://vercel.com/pricing)
- [Fluid Compute Pricing](https://vercel.com/docs/functions/usage-and-pricing)
- [Spend Management](https://vercel.com/docs/pricing#spend-management)
- [Limits](https://vercel.com/docs/limits)
- [Usage API](https://vercel.com/docs/rest-api)

## Next Steps

For reference architecture, see `vercel-reference-architecture`.
