---
title: "ResourceShark SDK"
description: "Choose a ResourceShark SDK entry point and create a typed client with the credential your code needs."
url: "https://agentpost.tools/docs/resourceshark/sdk"
kind: sdk
---

# ResourceShark SDK

`@agentpost-tools/resourceshark-sdk` is the TypeScript library for ResourceShark’s HTTP API. Its client uses `fetch` and runs in Node 24, browsers, and React Native.

```sh
npm i @agentpost-tools/resourceshark-sdk
```

## Entry points

| Import | What it provides |
| --- | --- |
| `@agentpost-tools/resourceshark-sdk` | `createClient`, request and response types, and [refusal readers](/docs/resourceshark/sdk/refusal-readers.md) |
| `@agentpost-tools/resourceshark-sdk/workflows` | A framework-independent [hold workflow](/docs/resourceshark/sdk/hold-workflow.md) and its transports |
| `@agentpost-tools/resourceshark-sdk/server` | The server-only [hold endpoint and payment helper](/docs/resourceshark/sdk/server.md) |
| `@agentpost-tools/resourceshark-sdk/helpers` | Opt-in [helpers](/docs/resourceshark/sdk/helpers.md) for recurring supply, totals, shortfalls, reversals, and slot times |
| `@agentpost-tools/resourceshark-react` | `useHoldWorkflow` and `useStore` for [React and React Native](/docs/resourceshark/sdk/hold-workflow.md#react) |

## Create a client

Use your project’s secret key on your server. Use a signed-in principal’s user token for supported reads of that principal’s holder records in a browser or app. Send page requests for slots and hold writes through [your server’s hold endpoint](/docs/resourceshark/sdk/server.md#create-a-hold-endpoint).

```ts
import { createClient } from '@agentpost-tools/resourceshark-sdk';

export function serverClient(key: string) {
  return createClient({ token: key });
}

export function holderClient(userToken: string) {
  return createClient({ token: userToken });
}
```

The client sends `token` as a bearer token. `baseUrl` defaults to `https://api.agentpost.tools/v1/resources`. Pass `fetch` to supply your own Fetch implementation or `headers` to add headers to each request.

Methods that accept `CallOptions` let you override `token` for that call. Where a write requires `WriteOptions`, supply `idempotencyKey` and reuse it when you retry the same write. Where a write requires `VersionedOptions`, supply the version you read as `ifMatch`. The client sends them as `Idempotency-Key` and `If-Match`. Find each call and its accepted credential in the [ResourceShark API reference](/docs/resourceshark/reference.md).

The client throws `ResourcesharkApiError` when the API answers with an error. [Refusal readers](/docs/resourceshark/sdk/refusal-readers.md) describes the error and the functions that read its details.
