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.
Async Lifecycle
Section titled “Async Lifecycle”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.
Webhooks
Section titled “Webhooks”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": "..." }.
Signature Verification
Section titled “Signature Verification”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=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bdVerify 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'))}Rate Limits
Section titled “Rate Limits”Hitfactor enforces per-organization sliding-window and concurrency limits:
| Limit | Default | Applies To |
|---|---|---|
| Requests per minute | 30 | All /api/v1/* and /api/v1/mcp tool calls |
| Concurrent async operations | 3 | Active queued or running async operations |
| Concurrent GPU-backed calls | 2 | generate_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).
Error Codes
Section titled “Error Codes”REST errors use { "error": { "code": "...", "message": "..." } }. MCP errors use JSON-RPC error: { "code": <rpcCode>, "message": "...", "data": { "code": "..." } }.
| HTTP | MCP Code | Error Code | Meaning |
|---|---|---|---|
400 | -32602 | invalid_input | Request body or arguments failed schema validation |
400 | -32602 | invalid_webhook_url | Webhook URL is not a valid public HTTPS URL |
401 | -32001 | unauthenticated / invalid_credentials | Missing, invalid, mixed, or revoked credentials |
402 | -32002 | insufficient_credits | Balance is lower than the tool cost (required, available) |
403 | -32003 | insufficient_scope | Key lacks the required scope (requiredScope) |
404 | -32004 | operation_not_found / not_found | Operation or route does not exist for this organization |
409 | -32009 | channel_sync_pending | Initial channel sync, avatars, or KB crawl is still running |
409 | -32010 | idempotency_conflict | Key was already used with different input or failed earlier |
409 | -32011 | idempotency_in_progress | Earlier call with this key is still running |
429 | -32029 | rate_limited | RPM or concurrency limit reached; wait Retry-After seconds |
500 | -32603 | internal_error | Tool failed; reserved credits were released |
501 | -32601 | not_implemented | Tool handler is unavailable |
503 | — | service_unavailable | Public API is temporarily disabled |