Home / Use cases / Cloudflare Workers
EU VAT validation in Cloudflare Workers
Run EU VAT validation at the Cloudflare edge with Workers. Store your API key as a Worker secret, validate VAT numbers globally with no cold starts, and cache results at the edge.
Implementation steps
- 1
Create a Worker with the standard fetch handler
- 2
Store TAXID_API_KEY as a Worker secret via wrangler secret put
- 3
Forward validation requests to the TaxID API with env.TAXID_API_KEY
- 4
Return the JSON response with Cache-Control headers for valid results
Code example
Workers (JS)
// Store your API key as a Worker secret:
// $ wrangler secret put TAXID_API_KEY
export default {
async fetch(request, env) {
const { searchParams } = new URL(request.url);
const country = searchParams.get('country');
const vat = searchParams.get('vat');
if (!country || !vat) {
return Response.json({ error: 'country and vat required' }, { status: 400 });
}
const res = await fetch(
`http://localhost:3000/api/v1/validate/${country}/${vat}`,
{ headers: { 'Authorization': `Bearer ${env.TAXID_API_KEY}` } }
);
const result = await res.json();
// Cache valid results at the Cloudflare edge for 1 hour
const ttl = result.valid ? 3600 : 0;
return Response.json(result, {
headers: { 'Cache-Control': ttl ? `max-age=${ttl}` : 'no-store' }
});
}
};cURL
# Test locally with wrangler:
# wrangler dev — then curl "http://localhost:8787?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:
{
"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.
activeVAT number is valid and the business is registered
invalidVAT number format is wrong or not registered in VIES
service_unavailableVIES or the national system is temporarily down — retry later
Evaluating EU VAT APIs? Compare TaxID vs Vatstack, Vatlayer, Avalara →
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...