Skip to Content

Async Operations

GET /v1/operations/:operationId — Check the status of an async operation.

Overview

PropertyValue
AuthBearer token (OIDC, must match tenant)
IdempotentN/A (read-only)

Operation States

queued → running → succeeded → failed → cancelled
StateDescription
queuedTask enqueued, waiting for worker
runningWorker is actively processing
succeededCompleted successfully, result available
failedProcessing failed, error details available
cancelledOperation was cancelled

Response (200)

{ "operation_id": "uuid", "request_id": "string", "tenant_id": "string", "endpoint": "proofread | essay-critique | onboarding-certify", "status": "queued | running | succeeded | failed | cancelled", "created_at": "ISO8601", "updated_at": "ISO8601", "completed_at": "ISO8601 | undefined", "provider": "gemini | undefined", "model": "string | undefined", "latency_ms": "number | undefined", "result": "object | undefined", "error": { "code": "string", "message": "string" } }

How Async Routing Works

  1. Request arrives at a core endpoint (proofread or essay-critique)
  2. If text exceeds SYNC_TEXT_THRESHOLD (1200 chars) or Prefer: respond-async header is set, the API routes to the async path
  3. An operation record is created with status queued
  4. The task is enqueued to Cloud Tasks (production) or an in-memory queue (development)
  5. A worker claims the operation and transitions it: queuedrunningsucceeded / failed
  6. The client polls /v1/operations/:id until a terminal state

Sync Timeout Fallback

If a sync request exceeds the SYNC_TIMEOUT_MS threshold (default 8000ms), the system automatically:

  1. Creates an operation record
  2. Enqueues the task for async processing
  3. Returns 202 with a poll_url

Polling Example

# Initial request returns 202 OPERATION_ID="op-uuid-from-response" # Poll until terminal state while true; do RESPONSE=$(curl -s "$GOTAMIL_API/v1/operations/$OPERATION_ID" \ -H "Authorization: Bearer $TOKEN") STATUS=$(echo "$RESPONSE" | jq -r '.status') echo "Status: $STATUS" if [ "$STATUS" = "succeeded" ] || [ "$STATUS" = "failed" ]; then echo "$RESPONSE" | jq . break fi sleep 2 done
Last updated on