# TypeScript SDK

Type-safe ByteKit client for Node.js and modern JavaScript runtimes.

The official TypeScript SDK is a thin, type-safe wrapper over the ByteKit REST API. It works
in Node.js and any runtime with a global `fetch` (Bun, Deno, Cloudflare Workers, modern
browsers).

## Install

```bash
npm install @hunt-labs/bytekit-sdk
```

Install `@hunt-labs/bytekit-sdk` (npm) / `bytekit-sdk` (PyPI). The npm package named `bytekit` is not ours.

## Initialize

```ts
import { ByteKit } from '@hunt-labs/bytekit-sdk';

const client = new ByteKit({
  apiKey: process.env.BYTEKIT_API_KEY!, // your sk_live_… key
});
```

## Your first scrape

```ts
const result = await client.scrape.create({
  url: 'https://example.com',
  formats: ['markdown'],
});

console.log(result);
```

## Capture a screenshot

```ts
const shot = await client.screenshots.create({
  url: 'https://example.com',
  full_page: true,
});

console.log(shot);
```

## Handle errors

Any 4xx/5xx response throws a `ByteKitError` carrying the HTTP `status` and the API
`error.code`:

```ts
import { ByteKit, ByteKitError } from '@hunt-labs/bytekit-sdk';

try {
  await client.scrape.create({ url: 'https://example.com' });
} catch (err) {
  if (err instanceof ByteKitError) {
    console.error(`${err.status} ${err.code}: ${err.message}`);
  } else {
    throw err;
  }
}
```

## Async scrapes

Pass `async: true` to enqueue the job and poll by ID:

```ts
const queued = await client.scrape.create({ url: 'https://example.com', async: true });
// later — poll with the returned sc_… id
const final = await client.scrape.get('sc_...');
```

## What's available

The client exposes one resource per capability: `scrape`, `screenshots`, `bulk`,
`fetch`, `monitors`, `sitemap`, `search`, `account`, `usage`, and `webhooks` (each with
`create` / `get` / `list` methods as applicable, plus nested resources like `scrape.bulk`
and `monitors.captures`).

See the [TypeScript SDK Reference](https://bytekit.com/docs/sdk/typescript/client) for every method and option.

## Next steps

- [Python SDK](https://bytekit.com/docs/libraries/python) — the same API surface in Python.
- [API Reference](https://bytekit.com/docs/api) — the underlying REST endpoints.
- [Errors](https://bytekit.com/docs/guides/errors) — error codes and retry guidance.