API Docs
Sentiment is a pay-per-request multilingual emotion API. Sign in with GitHub or Google, top up prepaid credit on the dashboard, create an API key, and each request debits your balance.
Authentication — API key
Create a key on the dashboard. The full key is shown once. Send it with each request, in either header:
Authorization: Bearer sent_...
X-API-Key: sent_...A key can analyze text, read your jobs and read your balance. It cannot buy credit or manage keys; those need a signed-in browser. You can revoke a key at any time on the dashboard.
Endpoints
GET /api/pricing— current price per message, GPU, model limits. Public.GET /api/balance— spendable balance + FIFO credit batches.POST /api/analyze— body{text, client_message_id?, keep_in_queue?}→{job_id, status}. Without enough credit, replies402 insufficient_balance. At capacity, replies503 no_capacity(never charged) unlesskeep_in_queue: true.POST /api/analyze/batch— body{texts: [...], client_message_id?, keep_in_queue?}(up toMAX_MESSAGES_PER_BATCH). Priced as the sum of the batch; billed in one debit, then split across RunPod calls automatically.GET /api/jobs/:id— job status +result(28 emotions + valence).202while queued/processing,200when terminal.GET /api/jobs?limit=&offset=— list your own jobs, newest first (only ever returns the authenticated account's jobs).
Response types
All responses are JSON. Success shapes below are written as TypeScript; fields are always present unless marked optional (?). Amounts ending in _atomic are integers in millionths of a US dollar, _usd are floats.
// POST /api/analyze — 202 Accepted (new job)
{
job_id: string, // UUID — poll GET /api/jobs/:id
status: "queued",
client_message_id: string | null,
cost_atomic: number,
estimated_cost_usd: number,
keep_in_queue: boolean
}
// Replays (same client_message_id) return 200/202 with the existing job:
// { job_id, status, client_message_id, result?, error?, replay?: true, message?: string }
// POST /api/analyze/batch — 202 Accepted
{
jobs: Array<{
job_id: string,
status: "queued",
client_message_id: string | null, // "<batch id>#<index>"
cost_atomic: number
}>,
total_cost_atomic: number,
total_cost_usd: number,
count: number,
keep_in_queue: boolean
}
// GET /api/jobs/:id — 202 while queued/processing, 200 when terminal
{
id: string,
status: "queued" | "processing" | "succeeded" | "failed",
client_message_id: string | null,
input_chars: number,
cost_atomic: number | null,
cost_usd: number,
result: Result | null, // see "Result shape" below; null until succeeded
error: string | null, // set when status = "failed"
created_at: string, // "YYYY-MM-DD HH:MM:SS" (UTC)
completed_at: string | null
}
// GET /api/jobs?limit=&offset= — 200
{
jobs: Array<Job & { input_text: string }>, // Job = the /api/jobs/:id body
total: number,
limit: number,
offset: number
}
// GET /api/balance — 200
{
account_id: string,
balance_atomic: number,
balance_usd: number,
tranches: Array<{ id: number, remaining_atomic: number, expires_at: string }>
}
// GET /api/pricing — 200
{
snapshot: {
price_per_msg_usd: number,
char_included: number,
price_per_extra_1k_chars_usd: number,
updated_at: string
},
model_limit: { max_chars_per_message: number, char_included: number, note: string },
quotes: Record<string, { chars: number, price_usd: number, price_atomic: number }>
}Errors share one envelope — {error: string, code: string, ...extras} — with a machine-readable code. Branch on code, not the message:
400 bad_text | bad_texts invalid text/texts (extras: index?, max_chars?)
401 auth_required missing, invalid or revoked API key
402 insufficient_balance extras: required_atomic, balance_atomic, topup_url
404 job_not_found job id unknown or owned by another account
409 batch_duplicate batch client_message_id already used — retry with a new id
413 text_too_long | batch_too_large extras: max_chars / max, got
429 rate_limited extras: retry_after_seconds (+ Retry-After header)
503 no_capacity queue full, nothing charged — extras: queue_depth,
max_queue_depth, retry_after_seconds (+ Retry-After header)
500 internal unexpected server errorCapacity, cancellation & refunds
By default, when we have no capacity your request is cancelled and refunded — you never pay for work we can't do. This happens at two points:
- At submit: if the queue is full, the request is refused with
503{code: "no_capacity", retry_after_seconds}before anything is debited — your balance is untouched. - While processing: if an accepted job can't reach a GPU worker in time, it is cancelled — the job ends as
failedwith ano capacityerror and the charge is automatically refunded to your balance as a 30-day credit tranche.
Prefer to wait instead? Set keep_in_queue: true on /api/analyze or /api/analyze/batch. Your job is then accepted regardless of queue depth and is never capacity-cancelled — it stays queued until a worker picks it up. Treat these submits as fully async: store the job_id, go do something else, and poll GET /api/jobs/:id (or list GET /api/jobs) later — don't block on a synchronous wait.
# Default: cancel + refund when at capacity
POST /api/analyze {"text": "...", "client_message_id": "uuid-1"}
→ 503 {"code": "no_capacity", "retry_after_seconds": 30, ...} # not charged
# Opt in to waiting: stays queued, poll asynchronously
POST /api/analyze {"text": "...", "client_message_id": "uuid-1", "keep_in_queue": true}
→ 202 {"job_id": "...", "status": "queued", "keep_in_queue": true}Rate limits
All /api/* routes are rate-limited per client IP (default 240 requests per 60s — comfortable for 1s polling). Exceeding it returns 429 {code: "rate_limited", retry_after_seconds} with a Retry-After header; current usage is reported via X-RateLimit-Limit / X-RateLimit-Remaining. Back off when you see 429s — for high-volume work, prefer /api/analyze/batch plus modest polling over hammering /api/analyze in a loop.
Result caching
Completed job responses are cached server-side (Redis): a result is served from cache until you fetch it once, or until ~10 minutes of no requests for it, whichever comes first. Eviction is purely a performance detail — every result is permanently persisted and GET /api/jobs/:id returns it again at any time. In-flight statuses are cached for ~2s, so a status you poll may lag reality by up to that long.
Result shape
The model uses sigmoid (multi-label), so scores are in [0,1] and do NOT sum to 1. There are 28 Go Emotions labels + a valence in [-1,1].
{
"text": "...",
"predictions": [ {"label": "joy", "score": 0.91}, ...28 total, sorted desc ],
"top_emotion": "joy",
"top_score": 0.91,
"valence": 0.82
}curl — submit a job
# 1. Submit.
curl -X POST https://emotions.togoder.click/api/analyze \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $SENTIMENT_API_KEY" \
-d '{"text":"I love this!","client_message_id":"uuid-1"}'
# 2. Poll with the returned job_id.
curl https://emotions.togoder.click/api/jobs/<job_id> \
-H "Authorization: Bearer $SENTIMENT_API_KEY"Python — sentiment analysis API example
# pip install requests
import os, time, uuid, requests
HOST = "https://emotions.togoder.click"
HEADERS = {"Authorization": f"Bearer {os.environ['SENTIMENT_API_KEY']}"}
def api_post(path: str, body: dict) -> dict:
r = requests.post(HOST + path, json=body, headers=HEADERS)
r.raise_for_status()
return r.json()
def api_get(path: str) -> dict:
r = requests.get(HOST + path, headers=HEADERS)
r.raise_for_status()
return r.json()
# Analyze one message (28 emotions + valence)
job = api_post("/api/analyze",
{"text": "I love this!", "client_message_id": str(uuid.uuid4())})
# Poll for the result
while True:
res = api_get(f"/api/jobs/{job['job_id']}")
if res["status"] not in ("queued", "processing"):
break
time.sleep(1)
print(res["result"]["top_emotion"], res["result"]["valence"])JavaScript
const HOST = "https://emotions.togoder.click";
const headers = {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.SENTIMENT_API_KEY}`,
};
const submit = await fetch(HOST + "/api/analyze", {
method: "POST",
headers,
body: JSON.stringify({ text: "I love this!", client_message_id: crypto.randomUUID() }),
});
const { job_id } = await submit.json();
let job;
do {
await new Promise((r) => setTimeout(r, 1000));
const r = await fetch(`${HOST}/api/jobs/${job_id}`, { headers });
job = await r.json();
} while (job.status === "queued" || job.status === "processing");
console.log(job.result);Batch — many messages in one request
POST /api/analyze/batch accepts up to MAX_MESSAGES_PER_BATCH (default 10000) texts at once. The total cost of the batch is debited in a single transaction (balance is checked first — the request fails with 402 insufficient_balance before any job is created if you can't cover the whole batch). Each text becomes its own job and is enqueued independently; the dispatcher then groups jobs into RunPod forward passes of RUNPOD_MAX_BATCH_SIZE, so a batch of N is split across ceil(N / RUNPOD_MAX_BATCH_SIZE) RunPod calls automatically.
Idempotency is per batch: pass one optional client_message_id for the whole request. It is stored per job as <id>#<index>; retrying the same batch id returns 409 batch_duplicate with no re-charge — use a new id to retry. Poll each returned job_id with GET /api/jobs/:id as usual.
# Body: {"texts": [...], "client_message_id"?: "batch-1", "keep_in_queue"?: true}
curl -X POST https://emotions.togoder.click/api/analyze/batch \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $SENTIMENT_API_KEY" \
-d '{"texts":["I love this!","This is awful"],"client_message_id":"batch-1"}'
# 202 Accepted — one job per text, in input order
{
"jobs": [
{"job_id":"...","status":"queued","client_message_id":"batch-1#0","cost_atomic":600},
{"job_id":"...","status":"queued","client_message_id":"batch-1#1","cost_atomic":600}
],
"total_cost_atomic": 1200,
"total_cost_usd": 0.0012,
"count": 2,
"keep_in_queue": false
}Top up credit
Top up on the dashboard by card, Apple Pay or Google Pay. Checkout is hosted by Polar, our merchant of record, which adds VAT or sales tax where it applies and provides receipts. The minimum is $10. The credit appears on your balance a few seconds after payment. Top-ups need a signed-in browser, so an API key can spend credit but cannot buy it.
Atomic amounts are millionths of a US dollar ($1 = 1,000,000 atomic). Top-up credit lasts 1 year, refund credit 30 days; debits consume the oldest tranche first (FIFO).