HALPIITax ID

HALPII Tax ID for JavaScript and TypeScript

Last reviewed 2026-11-21 · HALPII S.A.C.

The package @halpii/taxid is a client for the HALPII Tax ID API with complete types and no dependencies. It uses the platform fetch, so it runs in Node 18+, browsers, Deno, Bun and edge runtimes such as Cloudflare Workers, and ships ESM and CommonJS builds.

Status. Not on npm yet. The package @halpii/taxid is built and tested, but it is not published, so npm install @halpii/taxid does not work yet. To use it now, write to contacto@halpii.com and we send you the package file; or call the REST API with fetch, as at the end of this page.

Quick start

import { HalpiiTaxId } from '@halpii/taxid';

const taxid = new HalpiiTaxId({ apiKey: process.env.HALPII_TAXID_KEY });

const r = await taxid.check('PE', '20615614841'); // HALPII S.A.C.
r.assessment.verdict;    // 'pass' | 'review' | 'fail'
r.assessment.reasons;    // why, in plain words
r.verification_level;    // 'official_registry' | 'format_and_lists' | 'format'
r.legal_name;            // when the source publishes it

check(country, id) picks the endpoint for the country, and the return type narrows with it: a Peruvian answer is a RucResult, a Mexican one an RfcResult. The key travels in the X-API-Key header. For countries with several ID types, pass one: taxid.check('FR', 'FR00123456789', { idType: 'vat' }). A one-call shortcut is exported too: check('PE', '20615614841', { apiKey }).

Many IDs: checkBatch

The API checks one ID per request. checkBatch sends a few at a time (4 by default), keeps the order, sends repeated items once and never throws for a single item: each entry has ok: true with the result and verdict, or ok: false with the error. After a 429 that cannot be retried, or a 401, the remaining items are not sent.

const results = await taxid.checkBatch(
  [
    { country: 'PE', id: '20615614841' },
    { country: 'MX', id: 'XAXX010101000' },
  ],
  { concurrency: 4, onProgress: (done, total) => console.log(`${done}/${total}`) },
);

Methods

MethodAPI call
check(country, id, { idType? })The deepest check for that country
checkBatch(items, { concurrency?, stopOnLimit?, onProgress? })One lookup per item, a few at a time
peruRuc, mexicoRfc, colombiaNit, costaRicaCedulaThe four dedicated routes
countries()GET /v1/countries, not metered
usage(), limits()GET /v1/usage, GET /v1/limits (need a key; not lookups)
setDailyCap(n)PUT /v1/limits (Monthly plan)
createKey(email)POST /v1/keys: a no-cost key with 100 lookups a month

After each lookup, taxid.lastRateLimit holds the x-ratelimit-* headers.

Errors and retries

A malformed ID is not an exception: the API answers HTTP 400 with a lookup body, and the client returns it with format_valid: false and verdict fail. Anything else that is not a success throws a typed error: AuthenticationError (401), PermissionError (403), NotSupportedError (404), RateLimitError (429, with resetAt), SourceUnavailableError (503, not billed, with retryAfter) and ConnectionError.

import { RateLimitError, SourceUnavailableError } from '@halpii/taxid';

try {
  await taxid.check('PE', '20615614841');
} catch (e) {
  if (e instanceof RateLimitError) console.log('Limit reached until', e.resetAt);
  else if (e instanceof SourceUnavailableError) console.log('Try again in', e.retryAfter, 's');
  else throw e;
}

Retries are on by default. A 503 is retried after the seconds in Retry-After; a 429 is retried only when the limit resets within maxDelayMs. The allowance without a key and the month of a no-cost key reset much later, so they throw at once instead of keeping your process waiting.

new HalpiiTaxId({ apiKey, retry: { retries: 2, maxDelayMs: 60_000 } }); // the default
new HalpiiTaxId({ apiKey, retry: false });                               // never retry

Without the package

The API is one GET per lookup, so fetch is enough:

const res = await fetch('https://taxid.halpii.com/v1/pe/ruc/20615614841', {
  headers: { 'X-API-Key': process.env.HALPII_TAXID_KEY },
});
const result = await res.json();          // 200, or 400 with format_valid: false
console.log(result.assessment.verdict);
CountryEndpoint
Peru (RUC)GET /v1/pe/ruc/{ruc}
Mexico (RFC)GET /v1/mx/rfc/{rfc}
Colombia (NIT)GET /v1/co/nit/{nit}
Costa Rica (cédula)GET /v1/cr/cedula/{cedula}
Every other countryGET /v1/validate?country=XX&id=… (optional &id_type=…)

What the verdict means

VerdictMeaning
passRegistered and in good standing per the official source
reviewNeeds a human look: an unusual status, a not-found the source cannot rule out, or a check that stopped at the format. Mexico RFCs never get pass, because Mexico publishes no RFC registry
failMalformed, wrong check digit, not active, or on a tax-authority list

Do not ship your key to browsers you do not control: call the API from your server. The API allows cross-origin requests, so keyless calls from a page work too, within the small daily allowance per network.

MIT licence. Source: folder js of the halpii-taxid-integraciones repository. HALPII Tax ID is an independent service run by HALPII S.A.C. and is not affiliated with or endorsed by any tax authority.