Skip to Content

Documentation

SDKs

Install the TypeScript and Python SDKs, make your first call, page through lists and handle errors.

The official SDKs cover every endpoint in the API Reference, with typed parameters and answers. Both are generated from the OpenAPI spec and released with every change to the API.

LanguagePackageRuns OnTypes
TypeScript@socialapihq/sdkNode.js 18+, Bun, Deno
PythonsocialapihqPython 3.10+

The TypeScript SDK has no dependencies and uses the runtime's fetch. The Python SDK is synchronous, with Pydantic models. If you prefer plain HTTP, every example in these docs also has a cURL tab, and Authentication shows how to send your key.

Install

npm install @socialapihq/sdk

First Call

Create a client with your API key. Without one, it reads the SOCIALAPI_API_KEY environment variable.

profile.ts
import { SocialAPI } from "@socialapihq/sdk";

const client = new SocialAPI({ apiKey: process.env.SOCIALAPI_API_KEY });

const { data: profile } = await client.instagram.profile({ handle: "natgeo" });
console.log(profile.displayName, profile.followers);

To check your key for free, call client.account.getCredits() in TypeScript or client.account.get_credits() in Python. It answers your balance and costs nothing.

Naming

Each platform is a property of the client. Each endpoint is a method named after its path.

In the APITypeScriptPython
/v1/tiktok/…client.tiktokclient.tiktok
GET /v1/tiktok/post/comment/repliespostCommentReplies()post_comment_replies()
GET /v1/creditsaccount.getCredits()account.get_credits()
Parameter secUid{ secUid }sec_uid=
Field displayNamedisplayNamedisplay_name

TypeScript methods take one object of the endpoint's parameters, and Python methods take keyword arguments in snake case. Every platform method also takes maxAge (max_age in Python), the oldest cached answer you accept.

Answers

A method returns the answer's body, typed: { data } for one item, { data, pagination } for a list. The fields are the ones in Responses.

DetailTypeScriptPython
AnswerTyped objectPydantic model
TimesDatedatetime
Counts not shownnullNone
As plain JSONThe object itself.model_dump(by_alias=True)

A count the platform does not show is null, never 0, and what only one platform has is under ext, typed per platform.

Pagination

A list answers one page. Send pagination.nextCursor back as cursor for the next one, until there is none. Each page is a call of its own, charged like any other.

let cursor: string | undefined;
do {
  const page = await client.tiktok.profilePosts({ handle: "tiktok", cursor });
  for (const post of page.data) {
    console.log(post.id, post.stats.views);
  }
  cursor = page.pagination.nextCursor ?? undefined;
} while (cursor);

See Pagination for page sizes and limits.

Options

Both clients work with no options, and take a few when you need them.

OptionTypeScriptPythonDefault
API keyapiKeyapi_keySOCIALAPI_API_KEY
Base URLbaseUrlbase_urlhttps://api.socialapi.sh
Timeoutsignal on a calltimeout in secondsNone
Custom fetchfetchNoGlobal fetch
Extra headersheadersNoNone

In TypeScript, a method's second argument goes to fetch, so { signal: AbortSignal.timeout(10_000) } stops a call after 10 seconds.

In Python, the client keeps its connections open. Use it as a context manager (with SocialAPI() as client:), or call client.close() when you are done.

Errors

A refused call raises a SocialAPIError. Refused calls cost nothing.

FieldTypeScriptPython
HTTP statusstatusstatus
Stable codecodecode
Messagemessagemessage
Parameter at faultparamparam
Request idrequestIdrequest_id
Seconds to waitretryAfterretry_after

Branch on code, never on the message, and see Errors for every code. A network failure has status 0 and code NETWORK_ERROR. When you write to support, quote the request id.

import { SocialAPIError } from "@socialapihq/sdk";

try {
  await client.tiktok.profile({ handle: "no-such-account" });
} catch (error) {
  if (error instanceof SocialAPIError && error.code === "NOT_FOUND") {
    // No such account.
  } else {
    throw error;
  }
}

Versions

A new version is released whenever the API changes, so a new endpoint is a new method as soon as it ships. The code is on GitHub, in socialapihq/socialapi-node for TypeScript and socialapihq/socialapi-python for Python.

Next Steps