Usage examples for every resource live in the README. This page covers what the README doesn’t: what the SDK does on your behalf and the details worth knowing before you ship.
Install and verify
me() is free, so it is the quickest way to confirm your key works. It returns your credit balance and the capabilities of your plan.
require instead:
What the SDK handles for you
Good to know
Runtimes without process.env
The API key is read from process.env.COMPANYENRICH_API_KEY when that exists. On edge runtimes that expose secrets another way (Cloudflare Workers bindings, for example), pass it explicitly:
Retry timing
- Backoff starts at about 0.5 seconds, doubles on each attempt, and is capped at 8 seconds.
- On a 429, the SDK waits for the period the API specifies instead of guessing.
- If the API asks for a wait longer than 60 seconds, the SDK throws
RateLimitErrorright away so your process isn’t left hanging. Catch it and reschedule the work. - GET requests, and POST requests that cost nothing, are retried after a 408, a 5xx, a timeout, or a dropped connection.
- POST requests that consume credits or start a job are retried only on a 429. They are not repeated after a 5xx, timeout, or dropped connection, because the first attempt may already have been charged.
maxRetriescan be overridden per call, not only on the client. Pass{ maxRetries: 0 }as the last argument to turn retries off for a single request.
Timeouts and large downloads
timeoutMs covers the wait for a response to start. Once a bulk stream() or csv() download begins, the timer stops, so large exports are not cut off partway. If you break out of a stream() loop early, the SDK cancels the download.
Waiting for bulk jobs
batches.waitForCompletion() checks the batch every 2 seconds and waits indefinitely by default. In production, set a ceiling:
batches.get(id). To stop the job itself, call batches.cancel(id). Results that were already charged stay downloadable.
Person IDs are 64-bit
Person IDs can exceed what a JavaScriptnumber represents exactly. If you store IDs or receive them from another system, pass them to people.get() and people.findEmail() as a string or bigint to avoid silent rounding.
Proxies, testing, and tracing
baseUrlpoints the client at your own proxy or gateway.fetchaccepts any compatible implementation, which makes it easy to stub the API in unit tests without a mocking library.defaultHeaders(client) andheaders(per request) let you attach your own correlation IDs.- Requests identify themselves as
companyenrich-js/<version>. The same version string is exported asSDK_VERSION.
Types stay in sync with the API
Request and response types are generated from the public OpenAPI spec, so the fields you see in your editor are the fields the API returns. New API fields arrive in the SDK with the next release.Support
- Bugs and feature requests: GitHub issues
- When reporting a failed request, include the
traceIdfrom the error. It lets us find the exact call in our logs.