Home / Use cases / Vercel Edge

Vercel Edge

EU VAT validation on Vercel Edge

Add EU VAT validation to your Next.js app using Vercel Edge Functions. The edge runtime runs your validation globally with sub-50ms cold starts and built-in Next.js caching via next: { revalidate }.

Implementation steps

  1. 1

    Create an API route with export const runtime = 'edge'

  2. 2

    Store TAXID_API_KEY in your Vercel environment variables

  3. 3

    Call the TaxID API with next: { revalidate: 3600 } for edge caching

  4. 4

    Return NextResponse.json to your React frontend or webhook handler

Code example

Vercel Edge

// app/api/validate-vat/route.ts
// Runs at the Vercel edge — global, sub-50ms cold starts

import { NextRequest, NextResponse } from 'next/server';

export const runtime = 'edge';

export async function GET(request: NextRequest) {
  const { searchParams } = new URL(request.url);
  const country = searchParams.get('country');
  const vat     = searchParams.get('vat');

  if (!country || !vat) {
    return NextResponse.json(
      { error: 'country and vat params required' },
      { status: 400 }
    );
  }

  const res = await fetch(
    `http://localhost:3000/api/v1/validate/${country}/${vat}`,
    {
      headers: { 'Authorization': `Bearer ${process.env.TAXID_API_KEY}` },
      next: { revalidate: 3600 },  // cache validated results for 1 hour
    }
  );

  const result = await res.json();
  return NextResponse.json(result);
}

cURL

# Test locally:
# curl "http://localhost:3000/api/validate-vat?country=DE&vat=DE123456789"

# Or call the TaxID API directly:
curl "http://localhost:3000/api/v1/validate/DE/DE123456789" \
  -H "Authorization: Bearer $TAXID_API_KEY"

# {
#   "valid": true,
#   "status": "active",
#   "company_name": "Example GmbH",
#   "cached": false
# }

API response

The TaxID API returns a consistent JSON response for every validation request:

200 OK (active)valid
{
  "valid": true,
  "status": "active",
  "country_code": "DE",
  "vat_number": "123456789",
  "company_name": "Example GmbH",
  "company_address": "Musterstraße 1, 10115 Berlin",
  "request_date": "2026-05-10T00:00:00.000Z",
  "cached": false,
  "request_id": "req_01j..."
}

Error handling

The API uses a consistent Stripe-style error format. Always handle service_unavailable separately — VIES has occasional downtime and you should not reject valid customers during outages.

active

VAT number is valid and the business is registered

invalid

VAT number format is wrong or not registered in VIES

service_unavailable

VIES or the national system is temporarily down — retry later

Evaluating EU VAT APIs? Compare TaxID vs Vatstack, Vatlayer, Avalara →

Ready to implement?

Get your free API key and start validating EU VAT numbers today.

Get free API key

Related use cases

Validate EU VAT numbers in Stripe Checkout

Add EU VAT validation to your Stripe checkout flow. Verify customer VAT numbers server-side before a...

UK VAT validation in Shopify B2B

Validate UK VAT numbers for B2B customers in Shopify. Required under UK Making Tax Digital rules for...

WooCommerce Spain NIF/CIF validation

Validate Spanish NIF and CIF numbers in WooCommerce checkout. Automatically apply B2B tax exemptions...