> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datasite.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript API client

> Create a typed Datasite API client, call generated analytics operations, configure requests, use operation types, and handle API errors.

The `@datasite/api-client` package provides a typed TypeScript client for the Datasite API. Install it from npm before using the examples on this page.

```bash theme={null}
npm install @datasite/api-client
```

## Create a client

```ts theme={null}
import { DatasiteClient } from '@datasite/api-client';

const client = new DatasiteClient({
  baseUrl: 'https://app.datasite.sh',
  apiKey: process.env.DATASITE_API_KEY,
  timeout: 30_000,
});
```

## Call operations

```ts theme={null}
const websites = await client.statsListMyWebsites({});

const summary = await client.statsSummary({
  websiteId: 'YOUR_WEBSITE_ID',
  startAt: '2026-11-01T00:00:00.000Z',
  endAt: '2026-11-19T23:59:59.999Z',
});
```

Generated input types determine the accepted fields. The client replaces and URL-encodes path parameters, adds non-null query parameters, sends bearer authorization when configured, serializes a `body` as JSON, parses successful JSON responses, and applies the configured timeout.

## Options

| Option | Type | Default |
| - | - | - |
| `baseUrl` | `string` | Required |
| `apiKey` | `string` | None |
| `headers` | `HeadersInit` | None |
| `fetch` | `typeof fetch` | Global `fetch` |
| `credentials` | `RequestCredentials` | Fetch default |
| `timeout` | Positive number | `30000` milliseconds |

## Types

```ts theme={null}
import type {
  OperationInput,
  OperationOutput,
  Operations,
} from '@datasite/api-client';

type SummaryInput = OperationInput<'statsSummary'>;
type SummaryOutput = OperationOutput<'statsSummary'>;
```

## Errors

```ts theme={null}
import {
  DatasiteApiError,
  isDatasiteApiError,
} from '@datasite/api-client';

try {
  await client.statsSummary({
    websiteId: 'YOUR_WEBSITE_ID',
    startAt: '2026-11-01T00:00:00.000Z',
    endAt: '2026-11-19T23:59:59.999Z',
  });
} catch (error) {
  if (isDatasiteApiError(error)) {
    console.error(error.status, error.code, error.body);
  }
}
```

`DatasiteApiError` exposes `status`, `code`, `body`, `isNotFound`, and `isUnauthorized`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.