Skip to main content

Error Codes

This reference lists all error codes returned by the AgentGate API.

Error Response Format

{
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable description",
    "details": {
      // Additional context (varies by error)
    }
  }
}

Authentication Errors (401)

CodeDescriptionSolution
MISSING_API_KEYNo API key providedInclude Authorization: Bearer <key> header
INVALID_API_KEYAPI key format invalidCheck key format (should start with org_live_)
EXPIRED_API_KEYAPI key has been revokedCreate a new API key in dashboard
INVALID_API_KEY_FORMATMalformed authorization headerUse format Bearer <key>

Example

{
  "error": {
    "code": "INVALID_API_KEY",
    "message": "The provided API key is invalid"
  }
}

Authorization Errors (403)

CodeDescriptionSolution
INSUFFICIENT_PERMISSIONSKey lacks required scopeCreate key with needed scopes
SCOPE_REQUIREDSpecific scope neededCheck endpoint requirements
ORGANIZATION_SUSPENDEDOrganization access suspendedContact support

Example

{
  "error": {
    "code": "INSUFFICIENT_PERMISSIONS",
    "message": "API key lacks required scope",
    "details": {
      "requiredScope": "work-orders:write",
      "availableScopes": ["work-orders:read", "runs:read"]
    }
  }
}

Validation Errors (400)

CodeDescriptionSolution
INVALID_REQUESTRequest body invalidCheck request format
MISSING_FIELDRequired field missingInclude required field
INVALID_FORMATField format invalidCheck field requirements
INVALID_VALUEField value not allowedUse allowed values

Example

{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "Request validation failed",
    "details": {
      "errors": [
        {
          "field": "taskPrompt",
          "message": "must not be empty"
        },
        {
          "field": "workspaceSource.repository",
          "message": "is required when type is 'git'"
        }
      ]
    }
  }
}

Payment Errors (402)

CodeDescriptionSolution
INSUFFICIENT_CREDITSNot enough creditsPurchase more credits
BILLING_ERRORBilling configuration issueCheck billing settings

Example

{
  "error": {
    "code": "INSUFFICIENT_CREDITS",
    "message": "Insufficient credits to submit work order",
    "details": {
      "estimatedCost": 500,
      "availableCredits": 200
    }
  }
}

Not Found Errors (404)

CodeDescriptionSolution
RESOURCE_NOT_FOUNDResource doesn’t existCheck ID is correct
RUN_NOT_FOUNDRun ID not foundVerify run ID
WORK_ORDER_NOT_FOUNDWork order ID not foundVerify work order ID
WEBHOOK_NOT_FOUNDWebhook ID not foundVerify webhook ID
TEMPLATE_NOT_FOUNDTemplate ID not foundVerify template ID

Example

{
  "error": {
    "code": "RUN_NOT_FOUND",
    "message": "Run not found",
    "details": {
      "runId": "run_nonexistent"
    }
  }
}

Rate Limit Errors (429)

CodeDescriptionSolution
RATE_LIMITEDToo many requestsWait and retry
CONCURRENT_LIMITToo many concurrent runsWait for runs to complete

Example

{
  "error": {
    "code": "RATE_LIMITED",
    "message": "Rate limit exceeded",
    "details": {
      "limit": 100,
      "remaining": 0,
      "resetAt": "2024-01-15T10:35:00Z"
    }
  }
}
Headers included:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1705316100
Retry-After: 60

Server Errors (5xx)

StatusCodeDescriptionSolution
500INTERNAL_ERRORServer errorRetry with backoff
503SERVICE_UNAVAILABLEService temporarily unavailableRetry later
504TIMEOUTRequest timed outRetry

Example

{
  "error": {
    "code": "INTERNAL_ERROR",
    "message": "An unexpected error occurred",
    "details": {
      "requestId": "req_abc123"
    }
  }
}
Include the requestId when contacting support about server errors.

Run Error Codes

These codes appear in failed run results, not API responses.
CodeDescriptionCommon Causes
MAX_ITERATIONS_REACHEDDidn’t converge in timeComplex task, unclear prompt
VERIFICATION_FAILEDVerification never passedTest failures, type errors
WORKSPACE_ERRORWorkspace setup failedInvalid repo, missing access
EXECUTION_TIMEOUTRun took too longComplex task, slow tests
CANCELLEDUser cancelled runExplicit cancellation

Example (in run result)

{
  "id": "run_abc123",
  "status": "failed",
  "error": {
    "code": "MAX_ITERATIONS_REACHED",
    "message": "Run did not converge within 10 iterations",
    "details": {
      "iterations": 10,
      "lastVerificationResult": {
        "level": "L1",
        "passed": false,
        "failures": ["tests/user.test.ts failed"]
      }
    }
  }
}

Handling Errors

See Error Handling Guide for best practices.
try {
  await client.workOrders.create(/* ... */);
} catch (error) {
  switch (error.code) {
    case 'INSUFFICIENT_CREDITS':
      // Handle credit issues
      break;
    case 'RATE_LIMITED':
      // Wait and retry
      break;
    case 'INVALID_REQUEST':
      // Fix validation errors
      break;
    default:
      // Log and handle unknown errors
  }
}