API Reference
Error Handling
Understanding and handling Tork API errors in your applications.
Error Format
All API errors follow a consistent JSON format:
HTTP Status Codes
Standard HTTP status codes indicate the general category of error:
Error Codes
Specific error codes for programmatic handling:
invalid_api_keyThe API key provided is invalid or expired
Resolution: Check your API key in the dashboard
policy_violationAction was blocked by a governance policy
Resolution: Review the policy or request an exception
budget_exceededThe action would exceed the budget limit
Resolution: Wait for budget reset or increase limit
approval_requiredHuman approval is required for this action
Resolution: Wait for approval or check approval queue
circuit_breaker_openCircuit breaker is in open state
Resolution: Wait for cooldown or manual reset
rate_limit_exceededToo many requests in the time window
Resolution: Implement backoff and retry
agent_not_foundThe specified agent doesn't exist
Resolution: Register the agent first
invalid_policyPolicy configuration is invalid
Resolution: Check policy syntax and conditions
jailbreak_detectedJailbreak attempt was detected
Resolution: Review the input content
pii_detectedPII was found in the content
Resolution: Redact PII before proceeding
Error Handling Examples
These errors come from the Tork REST API, so you branch on the error.code in the response body. There is no Python cloud SDK — @torknetwork/sdk is npm-only, and tork-governance on PyPI decides on-device, so it returns a verdict rather than raising API errors. Handle the REST responses directly:
Retry Strategy
Implement exponential backoff for transient errors:
Debugging: Always log the request_id from error responses. Include it when contacting support.