CaptureKit

Node.js

Install the CaptureKit Node.js SDK and make your first API call.

The official Node.js SDK for CaptureKit, with one typed method per endpoint and a generic request() for anything else.

Requirements

  • Node.js 20+

Install

npm install @capturekitdev/sdk

Get your API key

Copy your API key from the CaptureKit dashboard and set it in the CAPTUREKIT_API_KEY environment variable, which the SDK reads by default. Keep it out of source control.

Quick start

import { CaptureKitClient } from "@capturekitdev/sdk";

const client = new CaptureKitClient({ apiKey: process.env.CAPTUREKIT_API_KEY });

const response = await client.content({ url: "https://example.com" });
console.log(response.data);

Async jobs

Any call accepts is_async, which is useful past the 60-second server limit. The response is then a job_id, and the SDK can wait for the job to finish.

const submitted = await client.content({
  url: "https://example.com",
  is_async: true,
});
const job = await client.waitForJob(submitted.data.job_id, {
  onProgress: (j) => console.log(`${j.status} ${j.progress ?? 0}%`),
});
console.log(JSON.stringify(job.data, null, 2));

Errors

A non-2xx response raises an API error with its status and message. See Status codes for the full list.

import { CaptureKitApiError } from "@capturekitdev/sdk";

try {
  await client.content({ url: "https://example.com" });
} catch (error) {
  if (error instanceof CaptureKitApiError) {
    console.error(error.status, error.message, error.responseBody);
  }
  throw error;
}

Retries

Requests are retried up to 3 times after a network error, a 408, 500, 502, 503 or 504, or a plan rate limit. Per-key quota errors and client-side timeouts are not retried. The delay starts at 1 second and grows 1.5× per retry, and a Retry-After header wins.

const client = new CaptureKitClient({ maxRetries: 5, retryDelay: 500 });

// or for one request
await client.content({ url: "https://example.com" }, { maxRetries: 0 });

Batch requests

Run many calls at once, 10 at a time by default. One failure does not stop the others.

const inputs = [
  "https://example.com",
  "https://www.capturekit.dev",
  "https://github.com",
];
const results = await client.batch(inputs, (url) => client.content({ url }), {
  concurrency: 5,
});

for (const result of results) {
  if (result.status === "fulfilled") console.log(result.value.data);
  else console.error(inputs[result.index], result.reason);
}

Any endpoint

request() reaches any path, including endpoints released after your SDK version.

const response = await client.request("GET", "/v1/usage");

Common mistakes

  • Putting the API key in front-end code. Anyone could read it. Call the API from your server.
  • Treating every 401 as a bad key. A 401 can also be a rate limit: read the message. The SDK retries plan rate limits for you.
  • Retrying a 402. It means there are no credits or quota left, so a retry cannot succeed. See Credits.
  • Waiting on long requests. Past 60 seconds, use async mode as shown above rather than raising your timeout. See Timeout.

On this page