@whereamimentioned/api-client is the typed client the CLI and the MCP bridge are built on, published on its own for scripts and integrations that want the API without the CLI. It is small on purpose: it sends the right headers, maps errors to a typed exception, retries the few things that are safe to retry, and otherwise gets out of the way. The types are the wire contract, and the server is tested against the same schemas.
Install
npm install @whereamimentioned/api-client
Node 20.19 or newer. ESM only. No dependencies on the server, the database or any secret.
Create a client
import { createWamClient } from "@whereamimentioned/api-client";
const wam = createWamClient({
baseUrl: "https://whereamimentioned.com",
token: process.env.WAM_TOKEN, // omit for the free site tools only
org: "acme", // sent as X-Wam-Org on organization-scoped calls
userAgent: "my-integration/1.0",
timeoutMs: 30_000, // default
});
| Option | Required | Meaning |
|---|---|---|
baseUrl |
yes | The API origin. https://whereamimentioned.com for production. |
token |
no | An API key. Leave it out to call only the free site tools. |
org |
no | The organization slug, sent as X-Wam-Org on every organization-scoped call. Required with an account-wide key; harmless with an organization key, where it must match. |
userAgent |
yes | Identifies your integration in the audit log. |
timeoutMs |
no | Per-request budget. Default 30 seconds. |
Make calls
Every method mirrors one endpoint of the reference and returns the typed body.
// Account
const me = await wam.me(); // GET /api/v1/me
const credits = await wam.credits(); // GET /api/v1/credits
// Organizations (account-wide keys only)
const orgs = await wam.organizations.list();
const created = await wam.organizations.create({ name: "Acme Labs", type: "brand" }, "orgcreate-acme-labs-1");
// Workspaces
const workspaces = await wam.workspaces.list({ limit: 50 });
const ws = await wam.workspaces.get("acme-main");
const made = await wam.workspaces.create("acme", { name: "Acme EU" }); // the org slug is explicit here
// Prompts and competitors
const prompts = await wam.prompts.list("acme-main", { enabled: "true", stage: "comparison" });
const prompt = await wam.prompts.create("acme-main", { text: "best AI visibility tools for agencies", intentStage: "comparison" });
await wam.prompts.patch("acme-main", prompt.id, { enabled: false });
await wam.prompts.remove("acme-main", prompt.id); // a 404 here resolves: the prompt is gone either way
const competitors = await wam.competitors.list("acme-main");
await wam.competitors.create("acme-main", { name: "Rival Co", domain: "rival.example", aliases: ["Rival"] });
// Scans
const estimate = await wam.scans.estimate("acme-main");
const scan = await wam.scans.create("acme-main", { quote: estimate.quote.token }, `nightly-acme-main-${today}`);
const status = await wam.scans.get(scan.id);
const page = await wam.scans.list("acme-main", { status: "done", limit: 10 });
const answers = await wam.scans.answers(scan.id, { mentioned: "false", limit: 100 });
// Reports: JSON returns the ReportData object, csv and pdf return bytes
const report = await wam.scans.report(scan.id, "json");
const csv = await wam.scans.report(scan.id, "csv"); // Uint8Array
// Recommendations and citations
const recs = await wam.recommendations.list("acme-main", { status: "open" });
const cites = await wam.citations.list("acme-main", { bucket: "third_party" });
// Keys
await wam.keys.revokeSelf(); // DELETE /api/v1/keys/self
// Free site tools: no key needed
const access = await wam.site.checkCrawlers("https://example.com");
const llms = await wam.site.validateLlmsTxt("https://example.com");
const generated = await wam.site.generateLlmsTxt("https://example.com", { full: false });
const sitemap = await wam.site.generateSitemap("https://example.com");
const schema = await wam.site.validateStructuredData("https://example.com/pricing");
const meta = await wam.site.checkMeta("https://example.com/pricing", "team pricing");
const chunks = await wam.site.analyzeChunks("https://example.com/blog/launch");
Two methods take an idempotency key as their last argument, scans.create and organizations.create, because the server requires one there. You supply it; the client does not invent one. After either call, wam.lastResponse.replayed tells you whether the server returned the original (201) or an existing resource (200 with X-Idempotent-Replay: true).
Pagination
List methods return { data, pagination }. Loop on pagination.nextCursor:
let cursor: string | undefined;
do {
const page = await wam.scans.list("acme-main", { limit: 100, cursor });
for (const scan of page.data) console.log(scan.id, scan.status, scan.score);
cursor = page.pagination.nextCursor ?? undefined;
} while (cursor);
Errors
Every non-2xx response, and any 2xx whose body is not JSON, is thrown as an ApiError:
import { ApiError, ApiTimeoutError, parseErrorDetails } from "@whereamimentioned/api-client";
try {
await wam.scans.create("acme-main", {}, key);
} catch (err) {
if (err instanceof ApiError) {
console.error(err.status, err.code, err.message, err.requestId);
if (err.code === "insufficient_credits") {
const d = parseErrorDetails("insufficient_credits", err.details);
if (d) console.error(`needs ${d.required}, has ${d.available}: ${d.billingUrl}`);
}
if (err.code === "scan_already_running") {
const d = parseErrorDetails("scan_already_running", err.details);
if (d) await wam.scans.get(d.scanId); // adopt the running scan
}
if (err.retryAfterSeconds !== null) {
// a 429: wait this long before trying again
}
} else if (err instanceof ApiTimeoutError) {
console.error(`${err.method} ${err.path} exceeded ${err.timeoutMs} ms`);
}
}
| Field | Type | Meaning |
|---|---|---|
status |
number | The HTTP status. |
code |
string | One of the twelve codes, or unknown for a non-JSON body. |
message |
string | The server's message. |
requestId |
string or null | From the body or the X-Request-Id header. |
details |
object or undefined | The code-specific payload, untyped. |
retryAfterSeconds |
number or null | From Retry-After or details.retryAfterSeconds on a 429. |
parseErrorDetails(code, details) narrows details to the typed shape the API defines for that code, or returns undefined when it does not match. It is how the CLI and the MCP server branch on details, and it means your code branches on what the API defines rather than on a locally guessed shape.
ApiTimeoutError is thrown when a request exceeds timeoutMs. It is never retried: you set that budget deliberately.
What the client does on your behalf
- Attaches
Authorization: Bearerand the API version header on every/api/v1call, andX-Wam-Orgon organization-scoped calls. SuppressesX-Wam-Orgon the three routes that resolve no organization (listing organizations, creating one, revoking the calling key). - Sends
Idempotency-Keyon the two routes that require it and on no other. - Retries idempotent
GETrequests only, at most twice (three attempts in total), with exponential backoff, on 502, 503, 504 and network failures. APOSTis never retried. A 429 is never retried:retryAfterSecondstells you when. - Aborts any request after
timeoutMs. - Exposes the last completed response's
status,headersandreplayedflag aslastResponse, and the lastX-Wam-Api-VersionandX-Request-Idseen.lastResponsedescribes the most recent request on that client instance, so read it before issuing the next call if you run requests concurrently.
What it does not do
- It does not validate response bodies at runtime. The exported types are the contract and the server is tested against the same Zod schemas; the client trusts them rather than paying for a second parse.
- It does not store tokens, read environment variables or find configuration files. Pass
tokenandorgexplicitly. The CLI does the discovery; this package does the wire. - It does not poll. Write the loop (ten seconds between polls is a sensible interval) or use
wam scan run --wait. - It does not generate idempotency keys.
Exports
Everything the wire needs is exported from the package root:
createWamClient,WamClient,WamClientOptions,ApiError,ApiTimeoutError,DEFAULT_BASE_URL,DEFAULT_TIMEOUT_MS,SUPPORTED_API_VERSION.- The response types:
Me,Credits,OrganizationSummary,CreateOrganizationResult,WorkspaceSummary,WorkspaceDetail,Competitor,Prompt,PromptListResponse,ScanSummary,ScanStatus,ScanEstimate,CreateScanResult,ScanAnswer,Recommendation,Citation,ReportData,RevokeSelfResult, and the seven site results (CrawlerAccessResult,LlmsTxtValidation,LlmsTxtGeneration,SitemapGeneration,StructuredDataValidation,MetaAnalysisResult,ChunkAnalysisResult). - The request types:
CreateOrganizationBody,CreateWorkspaceBody,CreateCompetitorBody,CreatePromptBody,PatchPromptBody,CreateScanBody, and the list query types. - The constants and enums:
API_ERROR_CODES,API_SCOPES,READ_ONLY_SCOPES,SCAN_STATUSES,INTENT_STAGES,REPORT_FORMATS,TIERS,QUOTE_TTL_SECONDS,ANSWER_TEXT_MAX_CHARS,ANSWER_CITATIONS_MAX, and the Zod schemas behind every type for callers who want to validate.
Package versions follow the CLI's: see the FAQ for the current release and the compatibility rule.