Skip to content
Agentpost robot in sunglasses on a red circleAgentpost

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.

npm i @agentpost-tools/resourceshark-sdk

Entry points

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

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.

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.

The client throws ResourcesharkApiError when the API answers with an error. Refusal readers describes the error and the functions that read its details.