Skip to content

Async Operations and Errors

Poll async operations, verify HMAC-SHA256 webhooks, and handle rate limits and error codes.

Four tools run asynchronously: critique_retention, generate_thumbnail, ideate_concepts, and generate_script.

When you call an async tool, Hitfactor reserves credits, queues a background job, and returns immediately:

{
"data": {
"operationId": "apiop_01...",
"status": "queued",
"pollUrl": "/api/v1/operations/apiop_01..."
},
"meta": {
"requestId": "req_01...",
"creditsCharged": 15,
"creditsRemaining": 485
}
}

REST returns HTTP 202. Poll GET /api/v1/operations/{operationId} or call MCP operation_get (0 credits) until status is succeeded or failed.

Operation statuses: queued, running, succeeded, failed, canceled. Operations remain available for 30 days.

Pass an optional webhookUrl field when calling any async tool. The URL must use https:// and resolve to a public IP address. Private, loopback, and .local / .internal hosts return 400 invalid_webhook_url.

When the operation finishes, Hitfactor sends a POST request with a JSON body:

{
"type": "operation.succeeded",
"data": {
"operationId": "apiop_01...",
"toolName": "generate_thumbnail",
"status": "succeeded",
"result": {},
"error": null,
"completedAt": "2026-12-01T20:15:00.000Z"
}
}

Failed operations send "type": "operation.failed" with result: null and error: { "code": "...", "message": "..." }.

When a webhook signing secret is provisioned for your beta workspace, Hitfactor signs every webhook with HMAC-SHA256 in the X-Hitfactor-Signature header (otherwise, webhooks are delivered unsigned):

X-Hitfactor-Signature: t=1700000000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd

Verify the signature against <timestamp>.<raw_body>:

import { createHmac, timingSafeEqual } from 'node:crypto'
function verifySignature(header: string, rawBody: string, secret: string): boolean {
const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')))
const t = parts.t
const v1 = parts.v1
if (!t || !v1) return false
const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex')
return timingSafeEqual(Buffer.from(v1, 'hex'), Buffer.from(expected, 'hex'))
}

Hitfactor enforces per-organization sliding-window and concurrency limits:

LimitDefaultApplies To
Requests per minute30All /api/v1/* and /api/v1/mcp tool calls
Concurrent async operations3Active queued or running async operations
Concurrent GPU-backed calls2generate_titles and generate_hooks

Responses include X-RateLimit-Limit and X-RateLimit-Remaining. Rate-limited responses (429) and 409 channel_sync_pending responses include Retry-After (in seconds).

REST errors use { "error": { "code": "...", "message": "..." } }. MCP errors use JSON-RPC error: { "code": <rpcCode>, "message": "...", "data": { "code": "..." } }.

HTTPMCP CodeError CodeMeaning
400-32602invalid_inputRequest body or arguments failed schema validation
400-32602invalid_webhook_urlWebhook URL is not a valid public HTTPS URL
401-32001unauthenticated / invalid_credentialsMissing, invalid, mixed, or revoked credentials
402-32002insufficient_creditsBalance is lower than the tool cost (required, available)
403-32003insufficient_scopeKey lacks the required scope (requiredScope)
404-32004operation_not_found / not_foundOperation or route does not exist for this organization
409-32009channel_sync_pendingInitial channel sync, avatars, or KB crawl is still running
409-32010idempotency_conflictKey was already used with different input or failed earlier
409-32011idempotency_in_progressEarlier call with this key is still running
429-32029rate_limitedRPM or concurrency limit reached; wait Retry-After seconds
500-32603internal_errorTool failed; reserved credits were released
501-32601not_implementedTool handler is unavailable
503—service_unavailablePublic API is temporarily disabled