OmniSocials Rust SDK
The official Rust client for the OmniSocials API. Schedule and publish posts to Instagram, Facebook, LinkedIn, YouTube, TikTok, X, Pinterest, Bluesky, Threads, Mastodon, and Google Business from one API.
- Async-first, built on
reqwestwith rustls (no OpenSSL needed) - Typed request params with serde, responses as
serde_json::Value - Automatic retries with exponential backoff, configurable timeouts
- A rich
Errorenum and a webhook signature verification helper
Installation
You also need an async runtime such as tokio:
Quickstart
use ;
async
Authentication
Create an API key in the OmniSocials app under Settings -> API Keys. Keys look like omsk_live_... (or omsk_test_...).
The client reads OMNISOCIALS_API_KEY from the environment, or you can pass one explicitly:
let client = new?;
Constructing a client without a key returns Error::Auth right away, with code missing_api_key.
Configuration
use Duration;
let client = builder
.api_key // wins over the env var
.base_url // default
.timeout // per-request timeout (default 30s)
.max_retries // retries on 429 / 5xx / network errors (default 2)
.build?;
Retries use exponential backoff (0.5s, 1s, 2s, ...) with jitter and honor the Retry-After header. Other 4xx responses are never retried.
Rate limits
The API allows 100 requests per minute per API key. When you exceed it, the SDK retries automatically (respecting Retry-After); if retries are exhausted it returns Error::RateLimit whose retry_after field holds the seconds to wait.
Return values
Methods return the parsed response body as-is, as a serde_json::Value: single items come back as {"data": {...}}, lists as {"data": [...], "pagination": {...}}, and some responses carry extra sibling keys (media uploads include compatibility, PDF uploads include slides and media_ids, post creates targeting X with a URL in the text include warnings). Endpoints that respond 204 No Content (deletes) resolve to Value::Null. Index into values with post["data"]["id"], or deserialize into your own structs with serde_json::from_value.
Posts
Schedule a post
use CreatePostParams;
let post = client.posts.create.await?;
println!;
Omit scheduled_at to create a draft. Use Content::PerPlatform for per-platform captions:
use HashMap;
use ;
client.posts.create.await?;
Publish immediately
client.posts.create_and_publish.await?;
Per-media alt text
Every media_urls / media_ids entry accepts either a plain string or a MediaEntry with an alt accessibility description (max 1500 chars): MediaEntry::Url for media_urls, MediaEntry::Id for media_ids. Alt text is delivered to Mastodon (media description), Bluesky (embed alt), X (photos and GIFs), Pinterest (pin alt text), Instagram (images), and LinkedIn (images). Plain and alt-carrying entries can be mixed via MediaEntry::Plain, and the same shape works in per-platform maps and thread_parts media.
use ;
client.posts.create.await?;
Post with platform-specific options
Platform option blocks are free-form JSON; build them with serde_json::json!:
use json;
client.posts.create.await?;
X thread
Provide 2 to 25 thread_parts to publish a chained thread instead of a single tweet. Each part is capped at 280 characters and can carry its own media (media_ids / media_urls, max 4 per part). The same thread_parts shape works for bluesky (300 chars per part) and mastodon (500 chars per part).
client.posts.create.await?;
On update, pass json!({ "thread_parts": null }) to clear thread mode (revert to a single post); omit the field to leave the existing thread untouched.
X link posts use credits
X bills API posts whose text contains a URL at a premium, and OmniSocials passes that fee through as prepaid credits (20 credits per URL-containing tweet; threads billed per part with a link). When a create targets X and the text contains a URL, the response carries a top-level warnings array (a sibling of data):
let res = client.posts.create.await?;
if let Some = res.as_array
From enforce_from (2026-08-14) the balance is checked at publish time, but credits are only deducted after the post successfully publishes (a failed publish is never charged). If the balance can't cover it, only the X target fails (other platforms publish normally); top up in the dashboard under Settings -> Organisation -> Billing -> Credits, then call posts().retry. Posts without links, analytics, and media on X stay free. There is no API endpoint for credits — they are managed in the dashboard.
List, get, update, publish, retry, delete
use ;
let posts = client.posts.list.await?;
let id = posts.as_str.unwrap;
let one = client.posts.get.await?;
client.posts.update.await?;
client.posts.publish.await?; // publish a draft/scheduled post now
client.posts.retry.await?; // retry only the failed platforms of a failed/warning post
client.posts.delete.await?; // resolves to Value::Null (204)
retry re-publishes only the platforms that failed, on the same post; platforms that already succeeded are never posted again. It is asynchronous: a 200 means the retry is queued, so poll get for the outcome. Max 3 retries per platform.
Recent platform posts
Fetch recent posts live from the connected platform APIs, including content published outside OmniSocials. Useful for brand-new workspaces where list is empty. Requires the analytics:read scope. Each record includes duration_seconds (integer, nullable): the video length in whole seconds where the platform reports it — currently TikTok and YouTube; null for images and for platforms that don't expose it.
use RecentPlatformPostsParams;
let recent = client.posts.recent_platform.await?;
Media
Upload from a URL (recommended, up to 1GB)
use UploadMediaFromUrlParams;
let upload = client.media.upload_from_url.await?;
println!;
Videos over 100MB are processed in the background and come back with status "processing". Every upload response includes a compatibility block listing connected platforms that would reject the file.
Upload local bytes (multipart)
use UploadMediaParams;
let bytes = read?;
let uploaded = client.media.upload.await?;
Direct multipart uploads are capped at 100MB by the CDN; use upload_from_url or the presigned flow below for bigger files.
Upload from base64
use UploadMediaFromBase64Params;
client.media.upload_from_base64.await?;
PDF carousels
Uploading a PDF rasterizes it into one image slide per page (max 20). The response carries slides and media_ids alongside data (the first slide). Pass ALL of media_ids, in order, to posts().create to post the deck as a carousel (a native swipeable document on LinkedIn, an image carousel elsewhere).
let pdf = client.media.upload_from_url.await?;
let media_ids: = from_value.unwrap;
client.posts.create.await?;
Presigned uploads for large files (up to 1GB)
create_upload_url mints a one-time upload URL. POST the file to it as multipart form data (field name file) within expires_in_seconds (600s); the second request needs no auth headers because the single-use token is in the URL. The response of that second request is the created media item (or media_ids for a PDF).
let minted = client.media.create_upload_url.await?;
let upload_url = minted.as_str.unwrap;
// Second leg with any HTTP client, e.g. reqwest:
let form = new.part;
let uploaded: Value = new
.post
.multipart
.send
.await?
.json
.await?;
println!;
Preflight compatibility check
Check a file against the workspace's connected platforms before uploading. Provide one of url, media_id, or size_bytes + mime.
use CheckMediaParams;
client.media.check.await?;
client.media.check.await?;
List, get, rename, move, delete
use ;
let items = client.media.list.await?;
let id = items.as_str.unwrap;
client.media.update.await?;
client.media.get.await?;
client.media.delete.await?; // 409 media_in_use if attached to a scheduled post
Folders
use ;
let folders = client.folders.list.await?; // flat; build the tree via parent_id
let folder = client.folders.create.await?;
let id = folder.as_str.unwrap;
client.folders.update.await?;
client.folders.delete.await?; // files move to root, subfolders move up
Hashtag Sets
Save reusable hashtag groups and apply them to posts at create time. Uses the posts:read / posts:write scopes.
use ;
let set = client.hashtag_sets.create.await?;
let id = set.as_str.unwrap;
println!; // "#saas #buildinpublic #startup"
client.hashtag_sets.list.await?;
client.hashtag_sets.get.await?;
client.hashtag_sets.update.await?;
client.hashtag_sets.delete.await?; // resolves to Value::Null (204)
Apply a set when creating a post with hashtag_set (the set name, case-insensitive) or hashtag_set_id. The set is applied once at create time and tags already in the caption are skipped. hashtag_placement is "caption_append" (default) or "first_comment", and hashtag_platforms restricts the hashtags to a subset of the post's channels. Instagram's 30-hashtag cap returns error code hashtag_limit_exceeded.
client.posts.create.await?;
Accounts
let accounts = client.accounts.list.await?;
for account in accounts.as_array.unwrap
let first_id = accounts.as_str.unwrap;
let one = client.accounts.get.await?;
Analytics
use ;
// One post's latest per-platform metrics
let stats = client.analytics.post.await?;
println!;
// Batch: up to 100 posts in one call
let batch = client.analytics.posts.await?;
// Workspace-wide overview
let overview = client.analytics.overview.await?;
println!;
// Account-level stats (followers etc)
let account_stats = client.analytics.accounts.await?;
Best times to post
use BestTimesParams;
let best = client.analytics.best_times.await?;
Locations (Instagram place tagging)
let results = client.locations.search.await?;
let place_id = results.as_str.unwrap;
let check = client.locations.validate.await?;
if check == true
Webhooks
Manage endpoints
use ;
let webhook = client.webhooks.create.await?;
println!; // save it, it is only shown once
let id = webhook.as_str.unwrap;
client.webhooks.list.await?;
client.webhooks.get.await?;
client.webhooks.update.await?;
let rotated = client.webhooks.rotate_secret.await?;
println!; // the old secret stops working
client.webhooks.delete.await?;
Verify deliveries (axum example)
Every delivery is signed with your webhook secret. The X-OmniSocials-Signature header has the form t=<unix>,v1=<hex> where the hex value is an HMAC-SHA256 of "{timestamp}.{rawBody}". Always verify against the RAW request body. The example uses axum (not a dependency of this crate):
use Bytes;
use ;
use post;
use Router;
async
let app: Router = new.route;
verify_signature uses a constant-time comparison, rejects timestamps older than the tolerance (300 seconds here; replay protection), returns Error::WebhookVerification on any failure, and returns the parsed event on success.
Health
let health = client.health.await?; // {"status": "ok", "version": "1.0.0", "timestamp": "..."}
Error handling
Every method returns Result<serde_json::Value, omnisocials::Error>. Non-2xx API responses map to the most specific variant, each carrying the status, the machine-readable code from the API body, the message, and the parsed body:
| Variant | Status | Typical API codes |
|---|---|---|
Error::Validation |
400 / 422 | validation_error, platform_not_connected, invalid_file_type |
Error::Auth |
401 | unauthorized, invalid_api_key |
Error::PermissionDenied |
403 | forbidden, insufficient_scope |
Error::NotFound |
404 | not_found |
Error::RateLimit |
429 | rate_limit_exceeded (exposes retry_after seconds) |
Error::Server |
>= 500 | internal_error |
Error::Api |
other non-2xx | e.g. 409 media_in_use |
Error::Connection |
n/a | network failure or timeout |
Error::WebhookVerification |
n/a | invalid webhook signature |
use ;
match client.posts.create.await
The err.status(), err.code(), and err.retry_after() accessors work across all API variants.
API scopes
Each API key carries scopes: posts:read, posts:write, media:write, accounts:read, analytics:read, webhooks:manage. A call with a missing scope returns Error::PermissionDenied with code insufficient_scope.
Documentation
Full API reference and guides: https://docs.omnisocials.com
License
MIT