Sajha API v1

Sajha API

Make posters from your own apps. JSON in, JSON out, under https://www.yukeshchaudhary.com/sajha/api/v1. The WordPress plugin uses the same API.

Keys

Make keys in the dashboard under API keys. Send one with every call:

Authorization: Bearer sjh_…

API keys (sjh_…)

For your own apps and servers. Need a package with API access. Each key has abilities: posters:create, posters:read, templates:read.

Site keys (sk_site_…)

For the WordPress plugin. Locked to the first site that connects, which must send its address in X-Site-Url on every call. Can do everything the plugin needs.

Keys are secrets. Keep them on your server; never put them in a web page or an app people can download. Sajha only stores a fingerprint, so a lost key can't be shown again: revoke it and make a new one.

Making a poster

Posters are drawn in a browser (so Nepali text is shaped perfectly), then uploaded. Sajha checks your package, caches every poster, and only counts a poster once: the same text and brand again comes straight from the cache, free.

  1. Prepare with your text. If it's cached you get the files right away ("cached": true).
  2. Otherwise you get one html_url per format. Load each in a browser at its exact size, wait for window.__sajhaReady, and capture a PNG (Sajha's sajha-render.js does this).
  3. Upload the PNGs to upload_url within 10 minutes. It works once and needs no key, so the browser can upload directly.
  4. If drawing fails, post to fail_url and the reserved poster returns to your quota. Renders that never come back are released after 10 minutes too.

Prepare

curl -X POST https://www.yukeshchaudhary.com/sajha/api/v1/posters/prepare \
  -H "Authorization: Bearer sjh_…" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "breaking-news-01",
    "formats": ["feed", "og"],
    "external_ref": "post:1842",
    "data": {
      "headline": "विश्वकप सपना मात्रै होइन",
      "image": "https://example.com/cricket.jpg",
      "date": "2026-10-31",
      "highlight_words": "सपना",
      "lang": "ne",
      "date_style": "bs",
      "show_brand_name": "1",
      "show_handle": "0"
    }
  }'

data holds the template's slots (see GET /templates) plus lang (ne, en), date_style (bs, ad) and the brand bar switches show_brand_name, show_handle and show_sponsor ("0" hides it). Image slots take a public http(s) link; Sajha fetches it through its image proxy. Add brand_kit_id to use a kit other than the default.

No browser on your side? Send "render": "server" (packages with auto mode). The answer is 202 with "queued": true and the poster's id; poll GET /posters/{id} until status is done. Nothing is charged until it is drawn.

Not cached yet

{
  "cached": false,
  "poster_id": 42,
  "poster": { "id": 42, "status": "rendering", "files": {}, … },
  "formats": {
    "feed": { "w": 1080, "h": 1350, "html_url": "https://yukeshchaudhary.com/sajha/t/breaking-news-01/render/feed?…" },
    "og":   { "w": 1200, "h": 630,  "html_url": "…" }
  },
  "upload_url": "https://www.yukeshchaudhary.com/sajha/api/v1/posters/42/files?nonce=…&signature=…",
  "fail_url": "https://www.yukeshchaudhary.com/sajha/api/v1/posters/42/fail?signature=…"
}

Upload

curl -X POST "$UPLOAD_URL" \
  -F "files[feed]=@feed.png" \
  -F "files[og]=@og.png"

Each PNG must be exactly the size from prepare. Sajha adds the watermark when the package needs one, and makes WebP and thumbnail copies.

Done (also what a cached prepare returns)

{
  "cached": false,
  "poster": {
    "id": 42,
    "status": "done",
    "template": "breaking-news-01",
    "source": "api",
    "external_ref": "post:1842",
    "share_url": "https://yukeshchaudhary.com/sajha/p/…",
    "files": {
      "feed": { "format": "feed", "w": 1080, "h": 1350, "png": "…/feed.png", "webp": "…/feed.webp", "thumb": "…/feed-thumb.webp", "bytes": 412345 },
      "og":   { … }
    }
  }
}

Endpoints

All paths are under https://www.yukeshchaudhary.com/sajha/api/v1. The second column says which key ability you need.

Account

GET/me

Workspace, package, expiry, quota used and left, features.

any key

GET/brand-kits

Brand kits in the workspace (default first).

templates:read

Templates

GET/templates

Templates this workspace can see, with slots, formats (and whether the package allows each), preview image. Filters: category, language (ne, en).

templates:read

GET/templates/{slug}/render/{format}

A signed, short-lived URL to the template page with your data[…], for a live preview. No poster is made, no quota is used.

templates:read

Posters

POST/posters/prepare

Check, look in the cache, reserve one poster. Returns the cached poster, or the pages to draw and where to upload them.

posters:create

POST/posters/prepare-bulk

Up to 50 items. Every item is checked and quota is reserved only if there is enough for all the new ones.

posters:create

POST/posters/{id}/files

Upload the drawn PNGs (multipart, files[feed], files[og]…) to the upload_url from prepare. Needs no key.

signed link

POST/posters/{id}/fail

Tell Sajha the drawing failed (error); the reserved poster goes back to your quota. Use the fail_url from prepare.

signed link

GET/posters

Finished posters, newest first. Filters: external_ref, status, per_page (max 100).

posters:read

GET/posters/{id}

Status and file URLs per format.

posters:read

DELETE/posters/{id}

Delete a poster and its files. Its share link stops working.

posters:create

WordPress sites (site keys only)

POST/sites/verify

Bind the key to the site in X-Site-Url (first call only) and get the account, quota and allowed templates. Body: plugin_version, wp_version.

site key

POST/sites/ping

Daily heartbeat with plugin_version and wp_version.

site key

Public

GET/plugin/latest

Latest sajha-poster plugin version, download URL and changelog.

none

Bulk prepare

POST https://www.yukeshchaudhary.com/sajha/api/v1/posters/prepare-bulk
{ "items": [
    { "template": "breaking-news-01", "formats": ["feed"], "external_ref": "post:1", "data": { "headline": "…" } },
    { "template": "quote-card-01", "formats": ["square"], "data": { "quote": "…" } }
] }

→ { "data": [ { …same as prepare… }, { … } ] }

If the new posters in the batch need more than you have left, nothing is reserved and you get quota_exceeded. Identical items share one poster.

Errors

Every error has the same shape. Show message to people; it is written for them.

{ "error": { "code": "quota_exceeded", "message": "You used all 200 posters this period. Ask to upgrade for more.", "upgrade_url": "https://yukeshchaudhary.com/sajha/billing?upgrade=1" } }
Code HTTP When
unauthenticated 401 No key, a wrong key, or a revoked key.
forbidden 403 The key may not do this (missing ability, or not a site key).
site_url_missing 400 Site keys must send X-Site-Url.
domain_mismatch 403 The site key belongs to another domain.
site_not_verified 403 Call /sites/verify first.
validation_failed 422 Something in the request is wrong; see fields.
missing_field 422 A required slot is empty.
invalid_formats 422 The template has no such format.
quota_exceeded 402 No posters left this period. Has upgrade_url.
package_expired 402 The package ended or is paused. Has upgrade_url.
feature_locked 402 The package does not include this (API access, a format, a template tier). Has upgrade_url.
upload_expired 410 The upload link was used already or is older than 10 minutes. Prepare again.
upload_incomplete 422 A format from prepare is missing in the upload.
invalid_upload 422 The PNG is not a PNG or not the right size.
not_found 404 No such poster, template or brand kit in this workspace.
conflict 409 That domain is already connected with another site key.
rate_limited 429 More than 60 requests a minute with one key. See Retry-After.

Limits

Stuck? Write to ive@yukeshchaudhary.com.