SDKs
UniPost has first-party SDKs for JavaScript, Python, and Go. This page shows how to install them, initialize a client, publish with the recommended request shape, validate drafts, work with analytics, and handle errors in each language.
Overview
The SDK pages should help a developer ship, not just confirm that a package exists. UniPost's SDKs all map to the same mental model: connect accounts, publish with platform_posts[], validate before publish, then add drafts, preview, and analytics.
Supported SDKs
| SDK | Best for | Status |
|---|---|---|
| JavaScript / TypeScript | Next.js apps, backend services, edge workers | Primary |
| Python | Automation, agents, data workflows | Primary |
| Go | Backend services and job runners | Primary |
Install
Pick the SDK that matches your runtime. If you just need raw HTTP examples, those belong in the API reference, not in the SDK guide.
npm install @unipost/sdkInitialize a client
Every SDK uses the same API key and the same resource model. Once the client is initialized, the rest of the examples translate directly across languages.
import { UniPost } from "@unipost/sdk";
const client = new UniPost({
apiKey: process.env.UNIPOST_API_KEY,
});List connected accounts
Most integrations start by listing accounts and selecting the right account_id. If you are building for end users, this is also where you look up accounts connected through UniPost Connect sessions.
const { data: accounts } = await client.accounts.list();
const twitterAccounts = await client.accounts.list({
platform: "twitter",
});Publish with the recommended request shape
Across every SDK, the recommended publishing shape is platform_posts[] plus idempotency_key. It keeps retries safe and lets you adapt caption tone per platform instead of flattening everything into one caption.
const post = await client.posts.create({
platformPosts: [
{
accountId: "sa_twitter_123",
caption: "Short version for X",
},
{
accountId: "sa_linkedin_456",
caption: "Longer version for LinkedIn with more context.",
},
],
idempotencyKey: "launch-2026-04-13-001",
});Validate before publish
Use validation before any automated publish, especially if your content comes from an LLM. UniPost checks platform-specific constraints before the request creates a post or touches downstream platforms.
const result = await client.posts.validate({
platformPosts: [
{
accountId: "sa_twitter_123",
caption: draftForX,
},
],
});
if (!result.valid) {
console.log(result.issues);
}Work with drafts
Drafts are the safest way to build review workflows. Save first, create a preview link if needed, then publish when your product or operator is ready.
const draft = await client.posts.create({
accountIds: ["sa_twitter_123"],
caption: "Work in progress",
status: "draft",
});
await client.posts.publish(draft.id);Read analytics
The SDKs expose both per-post analytics and workspace-level rollups. That gives you enough surface area to build dashboards, reports, and agent workflows without dropping into raw HTTP.
const analytics = await client.posts.analytics("post_abc123");
const rollup = await client.analytics.rollup({
from: "2026-04-01T00:00:00Z",
to: "2026-04-30T00:00:00Z",
granularity: "day",
});Handle errors
The JavaScript SDK exposes richer typed errors today, while Python and Go currently follow their host language's more conventional patterns. In every case, validation failures, auth issues, and rate limits should be handled explicitly.
import { AuthError, RateLimitError, UniPostError } from "@unipost/sdk";
try {
await client.posts.create({...});
} catch (error) {
if (error instanceof AuthError) {
console.error("Bad API key");
} else if (error instanceof RateLimitError) {
console.error("Retry after", error.retryAfter);
} else if (error instanceof UniPostError) {
console.error(error.status, error.code, error.message);
}
}Which SDK should you use?
| If you are building... | Recommended SDK | Why |
|---|---|---|
| A web app or backend in TypeScript | JavaScript / TypeScript | Best typed experience and the richest helper surface today |
| Automation, data workflows, or AI backends | Python | Natural fit for automation and model-heavy pipelines |
| A service, worker, or internal tool in Go | Go | Good fit for backend jobs and infrastructure-oriented services |