Tools
TypeScript SDK
`@groundsocial/sdk`: typed calls, paging, retries and the cost of every call.
npm i @groundsocial/sdkCreate a client
import { createClient } from '@groundsocial/sdk'
const client = createClient({ apiKey: process.env.GROUNDSOCIAL_API_KEY })| Option | Default | What it does |
|---|---|---|
apiKey | GROUNDSOCIAL_API_KEY | Your key. Pass null for keyless mode (pay per call with paymentHandler). |
baseUrl | GROUNDSOCIAL_API_URL, then the public API | Where to send calls. |
sessionToken | none | A dashboard session, for key management (a key can’t manage keys). |
maxRetries | 2 | Retries for 429, 5xx and network errors, honouring Retry-After. |
timeoutMs | 60000 | Per attempt. |
userAgent | none | Identifies your app in our logs. |
onResponse | none | Called after every call with its cost: creditsCharged, creditsRemaining, requestId, attempts. |
paymentHandler | none | Answers a 402 by paying (MPP or x402) and returning the headers to retry with. |
headers, fetch | none | Extra headers; a custom fetch. |
Keys are only sent over https or to a loopback address, unless you set allowInsecureTransport.
Reddit methods
| Method | Returns |
|---|---|
reddit.subreddit(name) | A subreddit (t5). |
reddit.subredditPosts(name, { sort, t, limit }) | Listing of posts. |
reddit.post(id, { sort, limit }) | { post, comments }. |
reddit.moreComments(postId, children, { sort }) | The expanded comments of a more item. |
reddit.user(name) | A user (t2). |
reddit.userPosts(name) / reddit.userComments(name) | Listings. |
reddit.searchPosts(q, { subreddit, sort, t }) | Listing of posts. |
reddit.searchSubreddits(q) | Listing of subreddits. |
Responses are Reddit’s own Thing and Listing JSON, typed from the OpenAPI document. client.call(operationId, input) calls any operation by id with one flat input object and returns { status, data, meta }.
Paging
Listing methods return a ListingPromise. Await it for one page; iterate it for more. Nothing is fetched or charged until you do one of the two, and each page is one call.
const page = await client.reddit.subredditPosts('typescript', { sort: 'new' })
for await (const post of client.reddit.subredditPosts('typescript').items({ maxItems: 250 })) {}
for await (const page of client.reddit.userComments('quiet_ops').pages({ maxPages: 5 })) {}Errors
Failures throw ApiError with code, status, message, hint, docsUrl, retryable, requestId, details and retryAfterSeconds. Use isApiError(err) to narrow. See Errors.
Accounts and signup
client.account(): credits left and which key is calling. Free.client.onboarding.signup({ agentName, purpose }): agent self-signup. Returns{ status: "created", api_key, … }or{ status: "challenge", challenge }; call again withchallengeTokenandanswer.client.onboarding.deviceStart(clientName)anddevicePoll(deviceCode): device login.client.onboarding.emailStart(email),emailVerify(email, code),me(),listKeys,createKey,revokeKey: dashboard calls with a session token.