TypeScript and JavaScript
Use the implemented server-side SDK for authorization, enforcement and approval reads.
@reqlo/sdk 0.3.0 is published on npm. Node.js 20.18+ and ESM are supported. Keep the client and its secret
project API key on a trusted server. CommonJS, browser use and other runtimes are not currently supported.
Install
npm install @reqlo/sdkImport the client with import { Reqlo } from "@reqlo/sdk". This beta supports authorization checks, enforcement
and approval reads. The API key determines the environment.
Check permission and run an action
Register your agent, resource type and action, then publish a policy in the same environment as your project key. Call ReQlo at your trusted tool-execution boundary after authenticating the user. Keep the checked resource and executed action identical, and supply only attributes that match the registered schemas.
import { Reqlo } from "@reqlo/sdk";
const reqlo = new Reqlo({ apiKey: process.env.REQLO_API_KEY! });
// Inside your authenticated backend handler:
const document = await loadDocumentForUser(session.userId, documentId);
const request = {
agent: { id: registeredAgentId },
subject: { id: session.userId, kind: "user" },
action: "documents.read",
resource: { type: "document", id: document.id },
};
const contents = await reqlo.enforce(request, () => readDocumentContents(document.id));The callback runs once only after an explicit, validated allow. A deny, approval requirement, HTTP error, timeout, cancellation or malformed response throws and leaves the action stopped. Exceptions from your callback propagate unchanged; the SDK never retries the protected action. Do not mutate the request while authorization is pending.
enforce(request) without a callback returns an allow decision or throws. Keep protected work after the awaited
call and do not catch an error and then continue execution.
Handle all three decisions
authorize(request) returns a typed Decision with allow, deny, or approval_required:
const decision = await reqlo.authorize(request);
if (decision.decision === "allow") {
return readDocumentContents(document.id);
}
if (decision.decision === "approval_required") {
await saveHeldRequest({ request, approvalId: decision.approval.id });
return { status: "waiting_for_approval" };
}
return { status: "blocked" };An HTTP error is thrown as an error, never converted into an allow or deny decision.
Read approvals and redeem one
const list = await reqlo.approvals.list({ status: "approved" });
const approval = await reqlo.approvals.retrieve(savedApprovalId);
if (approval.status === "approved") {
await reqlo.enforce({ ...savedOriginalRequest, approval_id: approval.id }, executeSavedAction);
}Lists return { data, environment_id }. Only the optional status filter is supported; there is no cursor
pagination. The project key determines the environment, so no environment_id is sent.
Approval and rejection require a person using the dashboard or CLI. Project keys and this SDK cannot resolve requests. Approval is redeemable once for the identical original request, and policy evaluation still runs. See Human approvals.
Record a delegation
When a person grants an agent authority in your app, record it, then send its ID with each request. Requires
@reqlo/sdk 0.2.0 or later. See Delegated access.
const delegation = await reqlo.delegations.create({
agent_id: "agt_calendar",
subject: { id: session.userId, kind: "user" },
actions: ["calendar.*"],
expires_at: new Date(Date.now() + 7 * 86_400_000).toISOString(),
});
await reqlo.enforce({ agent: { id: "agt_calendar" }, subject: { id: session.userId, kind: "user" },
action: "calendar.schedule", resource: { type: "calendar", id: calendarId }, delegation_id: delegation.id });
await reqlo.delegations.revoke(delegation.id); // when the person withdraws accessdelegations.list({ agent_id, subject_id }) and delegations.retrieve(id) read them back. Creating a delegation is
never retried automatically; after a timeout, list the person's delegations before trying again.
Verify webhooks
constructWebhookEvent (0.3.0 or later) checks the Reqlo-Signature header against the exact raw body and returns the
event, or throws ReqloSignatureError:
import { constructWebhookEvent, ReqloSignatureError } from "@reqlo/sdk";
export async function POST(request: Request) {
const body = await request.text(); // the raw body, before any JSON parsing
try {
const event = constructWebhookEvent(body, request.headers.get("Reqlo-Signature"), process.env.REQLO_WEBHOOK_SECRET!);
if (event.type === "approval.requested") await notifyApprovers(event.data.object.id);
} catch (error) {
if (error instanceof ReqloSignatureError) return new Response(null, { status: 400 });
throw error;
}
return new Response(null, { status: 204 });
}verifyWebhook(body, header, secret) returns true or false instead.
Configuration
| Option | Default | Meaning |
|---|---|---|
apiKey | Required | Secret project API key, supplied by your server |
baseUrl | https://api.reqlo.io/v1 | HTTPS URL ending in /v1; loopback HTTP allowed for development |
timeoutMs | 3000 | Per-attempt deadline, including response body consumption; 1–120000 |
maxRetries | 2 | Additional attempts after HTTP 429 or 5xx; 0–5 |
fetch | Platform fetch | Optional implementation for servers and tests |
Each operation accepts a final { signal: AbortSignal } option. For example:
await reqlo.authorize(request, { signal: controller.signal });
await reqlo.enforce(request, executeSavedAction, { signal: controller.signal });
await reqlo.approvals.list({ status: "pending" }, { signal: controller.signal });Retries and uncertain outcomes
Only HTTP 429 and 5xx are retried. Backoff is exponential with jitter; a valid Retry-After overrides it.
If the server asks for more than 10 seconds, the SDK surfaces the HTTP error rather than retrying early.
Network failures, timeouts and malformed successful responses are never retried.
Authorization is not idempotent: a retry after 5xx can create additional decision or approval records. If a
redemption response is lost, the approval may already be consumed. Set maxRetries: 0 when your workflow needs
to reconcile uncertain outcomes explicitly. Never assume an error means an action was allowed.
Typed errors
All SDK errors extend ReqloError:
| Error | Useful fields / meaning |
|---|---|
ReqloDeniedError | .decision contains the deny or approval-required result |
ReqloAPIError | .status, recognized .code, .requestId; raw upstream messages are not retained |
ReqloTimeoutError | Per-attempt timeout |
ReqloAbortError | Caller cancellation |
ReqloNetworkError | Fetch failure |
ReqloResponseError | Malformed successful response; never permission to act |
ReqloConfigurationError | Invalid options, approval ID or list filter |
Response types match the API reference. The SDK covers the project-key routes: authorize, approvals and delegations. Manage agents, policies and keys in the dashboard or with the CLI.
Something wrong or unclear? Report an issue with this page.