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.
| Language | Package | Runs On | Types |
|---|---|---|---|
| TypeScript | @socialapihq/sdk | Node.js 18+, Bun, Deno | |
| Python | socialapihq | Python 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/sdkFirst Call
Create a client with your API key. Without one, it reads the SOCIALAPI_API_KEY environment variable.
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 API | TypeScript | Python |
|---|---|---|
/v1/tiktok/… | client.tiktok | client.tiktok |
GET /v1/tiktok/post/comment/replies | postCommentReplies() | post_comment_replies() |
GET /v1/credits | account.getCredits() | account.get_credits() |
Parameter secUid | { secUid } | sec_uid= |
Field displayName | displayName | display_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.
| Detail | TypeScript | Python |
|---|---|---|
| Answer | Typed object | Pydantic model |
| Times | Date | datetime |
| Counts not shown | null | None |
| As plain JSON | The 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.
| Option | TypeScript | Python | Default |
|---|---|---|---|
| API key | apiKey | api_key | SOCIALAPI_API_KEY |
| Base URL | baseUrl | base_url | https://api.socialapi.sh |
| Timeout | signal on a call | timeout in seconds | None |
Custom fetch | fetch | No | Global fetch |
| Extra headers | headers | No | None |
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.
| Field | TypeScript | Python |
|---|---|---|
| HTTP status | status | status |
| Stable code | code | code |
| Message | message | message |
| Parameter at fault | param | param |
| Request id | requestId | request_id |
| Seconds to wait | retryAfter | retry_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.