Node.js SDK
Official SDK for Node.js and TypeScript. Supports all AIGodfather features.
fetch or any HTTP client — see the cURL / REST docs.Install (coming soon)
npm install aigodfather
Initialize
| Option | Type | Description |
|---|---|---|
apiKey | string | Required. Your API key |
baseUrl | string | API URL override (default: https://www.aigodfather.ai/api) |
debug | boolean | Log requests to console (default: false) |
timeout | number | Request timeout in ms (default: 10000) |
maxRetries | number | Auto-retry on 429/5xx (default: 3) |
defaultTags | string[] | Tags added to every event |
defaultMetadata | object | Metadata merged into every event |
onBlock | callback | Called when a rule blocks an action |
onApprovalRequired | callback | Called when approval is needed |
Methods
.info(message, metadata?)
Informational event. Low priority in Rules Engine.
.warning(message, metadata?)
Warning event. Medium priority.
.error(message, metadata?)
Error event. High priority — always evaluated by Rules Engine.
.critical(message, metadata?)
Critical event. Highest priority.
.track(eventType, options?)
Track a custom event type. Maps to event_type on the platform.
.action(actionName, options?)
Track a specific agent action. Maps to action field. Rules Engine evaluates action field for condition matching. Supports resource, amount, currency, requiresApproval.
.waitForApproval(approvalId, interval?, timeout?)
Poll an approval request until it resolves (approved/denied/expired).
.checkApproval(approvalId)
Single poll of an approval status.
.ping()
Test connectivity and retrieve agent info + usage limits.
Response Object
Every event method returns a Promise<EventResponse>:
| Field | Type | Description |
|---|---|---|
success | boolean | Event accepted |
status | string | "recorded" | "blocked" | "pending_approval" |
eventId | string | Event ID |
rulesMatched | number | How many rules fired |
incidentCreated | boolean | Whether an incident was opened |
approvalId | string? | Present when approval required |
aiClassification | object? | AI risk score and classification |
Error Handling
The SDK throws specific error classes for structured error handling:
| Error | HTTP | When |
|---|---|---|
BlockedError | 403 | Rule blocked the action |
PlanLimitError | 429 | Plan event limit reached |
AgentPausedError | 503 | Agent is paused |