Cleanlist TypeScript SDK (@cleanlist-ai/sdk)
Official TypeScript/JavaScript client for the Cleanlist API (v2) —
B2B lead discovery, waterfall enrichment, lead lists, smart agents, and export.
Generated from the public v2 OpenAPI schema (typescript-fetch), with a small Cleanlist
convenience facade so you can get productive in a few lines.
import { Cleanlist } from '@cleanlist-ai/sdk';
const cl = new Cleanlist({ accessToken: 'clapi_live_...' });
const me = await cl.workspace.whoami();
const list = await cl.leadLists.createList({ createListRequest: { name: 'Q3 outbound' } });
console.log(me.organization_name, list.list_id);
- ✅ Fully typed request & response models
- ✅ Works in Node 18+ and the browser (uses the platform
fetch)
- ✅ Ships CommonJS + ESM +
.d.ts
- ✅ Bearer-token auth, production defaults
- ✅ Generated from the same schema the API serves, so it never drifts
Table of contents
Installation
npm install @cleanlist-ai/sdk
Node 18+ (or any runtime with a global fetch). In older Node, pass a fetch
polyfill via fetchApi (see Configuration).
Authentication
Every request is authenticated with a Cleanlist API key, sent as an
Authorization: Bearer <key> header. Create one in the portal under
Settings → API Keys (keys start with
clapi_).
Pass it explicitly, or set CLEANLIST_API_KEY and let the client read it:
import { Cleanlist } from '@cleanlist-ai/sdk';
const cl = new Cleanlist({ accessToken: 'clapi_live_...' }); // explicit
const cl2 = new Cleanlist('clapi_live_...'); // shorthand
const cl3 = new Cleanlist(); // reads CLEANLIST_API_KEY
Keep keys secret. Never ship a clapi_ key in client-side browser code — proxy
Cleanlist calls through your backend.
Quickstart
import { Cleanlist } from '@cleanlist-ai/sdk';
const cl = new Cleanlist(); // CLEANLIST_API_KEY
// 1. Who am I? (identity, tier, scopes)
const me = await cl.workspace.whoami();
console.log(`Org: ${me.organization_name} | tier: ${me.tier}`);
// 2. Credit balance
const { credits } = await cl.workspace.creditsBalance();
console.log('credits:', credits);
// 3. Create a lead list
const list = await cl.leadLists.createList({ createListRequest: { name: 'Demo — API' } });
// 4. Enrich a person into it (async workflow — returns a handle)
const job = await cl.enrichment.enrichPerson({
enrichPersonRequest: {
lead_list_id: list.list_id,
first_name: 'Ada',
last_name: 'Lovelace',
company_name: 'Analytical Engines',
},
});
console.log('workflow:', job.workflow_id, '| reserved:', job.credits_reserved);
Response and request body fields are snake_case (they mirror the API exactly, e.g.
list_id, workflow_id, lead_list_id). The operation parameter wrappers are
camelCase (e.g. createListRequest, listId, workflowId).
Configuration
new Cleanlist(options) accepts:
| Option |
Default |
Description |
accessToken |
$CLEANLIST_API_KEY |
Your API key. Sent as Authorization: Bearer …. |
basePath |
https://api.cleanlist.ai |
API base URL. Use http://localhost:8000 for local dev. |
fetchApi |
platform fetch |
Custom fetch (e.g. node-fetch/undici on Node < 18, or a mock). |
maxAttempts |
3 |
Tries per request, the first included. 1 turns retries off. |
For advanced needs (middleware, custom headers), build a Configuration yourself and
pass it to the generated API classes — see
Using the generated API classes directly.
Core concepts
Credits & the estimate → quote flow
Search and list management are free; enrichment and smart-agent runs cost credits.
Bulk/paid operations (enrichList, runSmartAgent, and CSV import with enrichment)
require a signed quote from creditsEstimate first. The quote pins the price and is
single-use:
const quote = await cl.workspace.creditsEstimate({
estimateCostRequest: { tool: 'enrich_list', list_id: list.list_id, scope: 'full' },
});
console.log(`cost=${quote.estimated_cost} sufficient=${quote.sufficient}`);
if (quote.sufficient) {
const run = await cl.enrichment.enrichList({
enrichListRequest: { list_id: list.list_id, scope: 'full', quote_id: quote.quote_id },
});
console.log('bulk workflow:', run.workflow_id);
}
Enrichment scopes: partial (email + LinkedIn + title + company, 1 credit) ·
phone_only (10 credits) · full (email and phone, 11 credits). Pricing is
pay-for-results — the reservation is a cap and the unused portion is refunded.
Enrichment is asynchronous — poll for results
enrichPerson, enrichCompany, enrichByTask, and enrichList dispatch a workflow
and return a workflow_id. Poll enrichmentStatus until it settles:
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
const TERMINAL = ['completed', 'failed', 'cancelled'];
let status = await cl.enrichment.enrichmentStatus({ workflowId: job.workflow_id });
while (!TERMINAL.includes(status.status)) {
await sleep(3000);
status = await cl.enrichment.enrichmentStatus({ workflowId: job.workflow_id });
}
console.log('charged:', status.credits_charged, 'refunded:', status.credits_refunded);
Endpoint reference
The v2 surface is 26 operations across six resource groups, exposed on the Cleanlist
facade as cl.workspace, cl.leadLists, cl.peopleFinder, cl.enrichment,
cl.smartAgents, and cl.export. Field-by-field model docs live in docs/.
Workspace (cl.workspace)
| Method |
HTTP |
Description |
whoami() |
GET /api/v2/whoami |
Identity, org, tier, scopes & features. |
creditsBalance() |
GET /api/v2/credits/balance |
Spendable credit balance. |
creditsEstimate({ estimateCostRequest }) |
POST /api/v2/credits/estimate |
Price an op, get a signed quote. |
listApiKeys() |
GET /api/v2/api-keys |
List the org’s API keys. |
usageReport({ days?, groupBy? }) |
GET /api/v2/usage |
Credit-usage report. |
const me = await cl.workspace.whoami();
const usage = await cl.workspace.usageReport({ days: 30, groupBy: 'tool' });
const quote = await cl.workspace.creditsEstimate({
estimateCostRequest: { tool: 'enrich_person', scope: 'full', row_count: 1 },
});
Lead Lists (cl.leadLists)
| Method |
HTTP |
Description |
createList({ createListRequest }) |
POST /api/v2/lead-lists |
Create a list (idempotent on name). |
listLists({ folderId?, limit?, cursor? }) |
GET /api/v2/lead-lists |
List your lists (paginated). |
getList({ listId }) |
GET /api/v2/lead-lists/{list_id} |
Fetch one list. |
updateList({ listId, publicLeadListUpdate }) |
PATCH /api/v2/lead-lists/{list_id} |
Rename / move / edit. |
deleteList({ listId }) |
DELETE /api/v2/lead-lists/{list_id} |
Delete a list. |
listLeadsInList({ listId, limit?, cursor? }) |
GET …/{list_id}/leads |
Page through leads. |
addLeadsToList({ listId, body }) |
POST …/{list_id}/leads |
Add leads by id or cohort. |
removeLeadsFromList({ listId, removeLeadsRequest }) |
DELETE …/{list_id}/leads |
Remove up to 100. |
csvImport({ listId, csvImportRequest }) |
POST …/{list_id}/csv-import |
Import from base64 CSV. |
findPeople({ listId, findPeopleRequest }) |
POST …/{list_id}/find-people |
Find + import people at the list’s companies (async). |
findPeopleStatus({ listId, workflowId }) |
GET …/{list_id}/find-people/status/{workflow_id} |
Poll a find-people job. |
const list = await cl.leadLists.createList({ createListRequest: { name: 'Prospects — West' } });
const page = await cl.leadLists.listLeadsInList({ listId: list.list_id, limit: 100 });
// `body` is a one-of: pass lead_ids OR a search cohort (task_id)
await cl.leadLists.addLeadsToList({ listId: list.list_id, body: { lead_ids: ['lead_a', 'lead_b'] } });
await cl.leadLists.removeLeadsFromList({
listId: list.list_id,
removeLeadsRequest: { lead_ids: ['lead_a'] },
});
People Finder (cl.peopleFinder)
Search people by filters. Searching is free; credits are spent only when you enrich or save.
| Method |
HTTP |
Description |
searchPeople({ peopleSearchRequest }) |
POST /api/v2/people/find |
Search people by structured criteria (paginated). |
searchFiltersPeople({ field, query? }) |
GET /api/v2/people/find/filters |
Valid values / autocomplete for a filter field. |
compileSearch({ compileRequest }) |
POST /api/v2/people/find/compile |
Dry run: show the compiled filter without searching. |
companiesFindStart({ peopleByCompaniesRequest }) |
POST /api/v2/people/find-at-companies |
Start an async “find people at these companies” search. |
companiesFindStatus({ taskId }) |
GET /api/v2/people/find-at-companies/status/{task_id} |
Poll that search. |
import type { PeopleSearchCriteria } from '@cleanlist-ai/sdk';
const seniority = await cl.peopleFinder.searchFiltersPeople({ field: 'seniority' });
const titles = await cl.peopleFinder.searchFiltersPeople({ field: 'titles', query: 'vp sales' });
const criteria: PeopleSearchCriteria = {
jobTitlesInclude: ['VP of Sales'],
seniority: ['Vice President'],
contactCountries: ['USA'],
};
const preview = await cl.peopleFinder.compileSearch({ compileRequest: { criteria } });
const page = await cl.peopleFinder.searchPeople({ peopleSearchRequest: { criteria, limit: 25 } });
for (const row of page.results) console.log(row.full_name, row.title, row.company);
Enrichment (cl.enrichment)
| Method |
HTTP |
Description |
enrichPerson({ enrichPersonRequest }) |
POST /api/v2/enrichment/person |
Enrich one contact into a list. |
enrichCompany({ enrichCompanyRequest }) |
POST /api/v2/enrichment/company |
Enrich a company. |
enrichByTask({ enrichByTaskRequest }) |
POST /api/v2/enrichment/by-task |
Enrich entities from a prior task. |
enrichList({ enrichListRequest }) |
POST /api/v2/enrichment/bulk |
Bulk-enrich a list (needs quote_id). |
enrichmentStatus({ workflowId }) |
GET /api/v2/enrichment/status/{workflow_id} |
Poll a workflow. |
const job = await cl.enrichment.enrichPerson({
enrichPersonRequest: { lead_list_id: list.list_id, linkedin_url: 'https://linkedin.com/in/ada' },
});
const company = await cl.enrichment.enrichCompany({ enrichCompanyRequest: { domain: 'stripe.com' } });
Smart Agents (cl.smartAgents)
| Method |
HTTP |
Description |
runSmartAgent({ runSmartAgentRequest }) |
POST /api/v2/smart-agents/run |
Run an agent as a new AI column (needs quote_id). |
listSmartAgents({ listId?, limit? }) |
GET /api/v2/smart-agents |
Recent agent runs. |
getSmartAgentResults({ smartAgentTaskId }) |
GET /api/v2/smart-agents/{smart_agent_task_id} |
Per-lead output. |
const quote = await cl.workspace.creditsEstimate({
estimateCostRequest: { tool: 'run_smart_agent', list_id: list.list_id, agent_type: 'custom_ai', row_count: 50 },
});
const run = await cl.smartAgents.runSmartAgent({
runSmartAgentRequest: {
list_id: list.list_id,
agent_type: 'custom_ai',
column_name: 'Personalized angle',
prompt: 'In one sentence, suggest a cold-outreach angle for this lead.',
max_rows: 50,
quote_id: quote.quote_id,
},
});
const results = await cl.smartAgents.getSmartAgentResults({ smartAgentTaskId: run.smart_agent_task_id });
Export (cl.export)
| Method |
HTTP |
Description |
exportCsv({ exportCsvRequest }) |
POST /api/v2/export/csv/signed-url |
Export to CSV; returns a signed URL. |
exportJson({ listId, limit?, cursor?, columns? }) |
GET /api/v2/export/json |
Export rows inline as JSON. |
const signed = await cl.export.exportCsv({ exportCsvRequest: { list_id: list.list_id } });
console.log('download:', signed.download_url); // valid until signed.expires_at
const data = await cl.export.exportJson({ listId: list.list_id, limit: 500 });
for (const row of data.leads) console.log(row);
Actions, agents, plays, tasks, inbox, data and webhooks
| Property |
Class |
Covers |
cl.actions |
PublicActionsApi |
GET /api/v2/actions, run an action by name, confirm a card. |
cl.gtmAgents |
PublicGTMAgentsApi |
Agents, turning one on or off, live runs, run records. |
cl.plays |
PublicPlaysApi |
Plays, play runs, play events. |
cl.tasks |
PublicGTMTasksApi |
GTM tasks and the updates feed. |
cl.inbox |
PublicInboxApi |
Inbox threads and replies. |
cl.signals |
PublicSignalsApi |
Job postings, job changes, LinkedIn posts and engagers, technology adoption, company signals. |
cl.accountsData |
PublicAccountsDataApi |
Buying committee, org structure, meetings. |
cl.webhooks |
PublicWebhooksApi |
Webhook subscriptions and deliveries. |
Batch lookups (batchPeopleLookup, batchCompaniesLookup) are on cl.enrichment, and the
request log (listRequestLogs) is on cl.workspace. Live events are a WebSocket
(/api/v2/events/listen), not part of this client.
Turning an agent on, a live agent run and a play run spend credits and can send email or
write to a CRM, so each takes a signed quote_id, a key whose scopes allow what the run
does, and commit: true. Without commit you get a preview of what it would do.
const preview = await cl.gtmAgents.runGtmAgent({ agentId, runGtmAgentBody: { quote_id } });
const run = await cl.gtmAgents.runGtmAgent({ agentId, runGtmAgentBody: { quote_id, commit: true } });
Examples
Runnable scripts live in examples/ (setup notes in
examples/README.md). Run one with npx tsx examples/<file>.ts; each
reads CLEANLIST_API_KEY and an optional CLEANLIST_HOST. Type-check them all with
npx tsc -p examples.
Retries, idempotency and rate limits
GET, HEAD and OPTIONS are retried on network errors, 429 and 5xx, with backoff that honors
Retry-After (a wait over a minute is returned to you instead). POST, PUT, PATCH and DELETE
are retried only on a 429, a 503 idempotency_unavailable, or a network error with no
response when the request carries an Idempotency-Key, because any other 5xx may mean the
write already ran. POST /api/v2/actions/confirm and inbox replies are never retried.
Every POST, PATCH and DELETE carries an Idempotency-Key that stays the same across its
retries. To set your own:
import { withIdempotencyKey } from '@cleanlist-ai/sdk';
await cl.leadLists.createList({ createListRequest: { name: 'Q3' } }, withIdempotencyKey('order-1234'));
The API keeps a key for 24 hours, per API key and route. The same key with a different
body is a 422 idempotency_key_mismatch, and a repeat while the first is still running is
a 409 idempotency_in_progress.
After any call, cl.lastResponse has the rate-limit headers and the mode:
cl.lastResponse?.rateLimit; // { limit, remaining, reset } (reset is unix seconds)
cl.lastResponse?.idempotentReplayed; // true when the server replayed a stored response
cl.mode; // 'test' for a clapi_test_ key, else 'live'
readResponseMeta(response) reads the same values off any Response, such as
ResponseError.response.
Verifying webhooks
import { verifyWebhookSignature } from '@cleanlist-ai/sdk';
// rawBody: the request body exactly as received, not re-serialized JSON.
const ok = await verifyWebhookSignature(rawBody, req.headers['cleanlist-signature'], process.env.CLEANLIST_WEBHOOK_SECRET!);
if (!ok) return res.status(400).end();
Signatures older than 5 minutes are refused ({ toleranceSeconds } changes that).
Error handling
Non-2xx responses throw a ResponseError carrying the raw fetch Response:
import { ResponseError } from '@cleanlist-ai/sdk';
try {
await cl.leadLists.getList({ listId: 'does-not-exist' });
} catch (err) {
if (err instanceof ResponseError) {
console.error('API error', err.response.status);
const body = await err.response.json().catch(() => ({}));
console.error(body);
} else {
throw err;
}
}
List endpoints return a page plus an opaque cursor. Pass it back for the next page; a
falsy cursor means you’ve reached the end:
let cursor: string | null | undefined;
do {
const page = await cl.leadLists.listLeadsInList({ listId: list.list_id, limit: 500, cursor: cursor ?? undefined });
for (const lead of page.leads) {
// ...
}
cursor = page.cursor;
} while (cursor);
Using the generated API classes directly
The Cleanlist facade is optional sugar. Wire the generated pieces yourself if you prefer:
import { Configuration, PublicWorkspaceApi } from '@cleanlist-ai/sdk';
const config = new Configuration({
basePath: 'https://api.cleanlist.ai',
accessToken: 'clapi_live_...',
});
const workspace = new PublicWorkspaceApi(config);
console.log(await workspace.whoami());
Regenerating from the schema
This SDK is generated with openapi-generator-cli
(typescript-fetch, pinned in openapitools.json). To refresh after an API change:
# 1. Drop the latest openapi/cleanse-api-v2.oas.json in place, then:
npm run generate # cleans operationIds, regenerates src/, re-applies the facade
npm test # builds, then runs test/*.test.js
The generator needs a Java runtime (11 or later) on PATH.
Support
Licensed under the MIT License.
评论