TypeScript SDK
The official TypeScript and Node.js client for the FoPost API.
@fopost/sdk is the official TypeScript client. It ships ESM and CommonJS builds with full type definitions, and needs Node 18 or newer.
npm install @fopost/sdkThis is a 0.x release. The surface is still settling and a minor version may break something. Pin an exact version if that matters to you.
Published on npm. Source and issues: github.com/fopost/fopost-js. MIT licensed.
Quick start
import { FoPost } from '@fopost/sdk';
const fopost = new FoPost({ apiKey: process.env.FOPOST_API_KEY! });
const workspaces = await fopost.workspaces.list();
const accounts = await fopost.accounts.list({ workspaceId: workspaces[0].id });
const post = await fopost.posts.create({
workspaceId: workspaces[0].id,
content: [{ text: 'Hello from the SDK' }],
accounts: accounts.map((a) => a.id),
});
await fopost.posts.publish(post.id);publish returns as soon as delivery is queued. Read fopost.posts.deliveries(post.id) or subscribe to webhooks for the outcome.
Schedule instead
await fopost.posts.create({
workspaceId,
status: 'scheduled',
scheduleAt: '2026-09-02T09:00:00Z',
content: [{ text: 'Doors open Monday.' }],
accounts: [accounts[0].id],
});Times are UTC. Convert before sending.
Threads and media
More than one content block makes a thread:
await fopost.posts.create({
workspaceId,
accounts: [accounts[0].id],
content: [
{ text: 'What we learned shipping this quarter.' },
{
text: 'The chart that changed our minds.',
media: [{ type: 'image', name: 'chart.png', url: 'https://.../chart.png' }],
},
],
});What is on the client
| Namespace | Methods |
|---|---|
fopost.posts | list, get, create, update, delete, publish, cancel, retry, preflight, deliveries |
fopost.accounts | list, get, health |
fopost.workspaces | list, get |
fopost.labels | list |
fopost.ai | credits, generateCaption, rewrite, repurposeUrl |
On fopost.ai, only credits and generateCaption work with an API key today.
rewrite and repurposeUrl reach endpoints that require a dashboard session
and will answer 401. Use the composer for those until a later release.
Configuration
new FoPost({
apiKey: process.env.FOPOST_API_KEY!,
baseUrl: 'https://api.fopost.com',
fetch: customFetch,
});Keep the key server side. An SDK call from browser code ships the key to everyone who loads the page.
Errors
Failed requests throw with the status and the API's error code, so you can branch on the code rather than parsing a message. 402 means AI credits ran out and should not be retried; 429 carries Retry-After.
Next
Related documentation
- SDKs & Integrations
Official FoPost clients for TypeScript, Python, PHP, Ruby, Go, Rust, Java, .NET, Swift, Kotlin, Dart, and Elixir, framework integrations from Laravel to Next.js, and tooling for the CLI, CI, Terraform, and the automation platforms.
- SDKs Overview
Every official FoPost client, what it covers, and how to pick one.
- Python SDK
The official Python client for the FoPost API.
- PHP SDK
The official PHP client for the FoPost API, with no framework and no HTTP library.
- Ruby SDK
The official Ruby client for the FoPost API, with no runtime dependencies.
- Go SDK
The official Go client for the FoPost API.
- Rust SDK
The official Rust client for the FoPost API, async and built on reqwest.
- Java SDK
The official Java client for the FoPost API, on the JDK's own HTTP client.