Skip to main content
The @pecta/core SDK runs quality gates entirely inside your Node.js process. There is no network call on the hot path: gates execute in parallel, the engine returns a result object, and telemetry ships to Pecta cloud asynchronously in a background batch. This makes the SDK the right choice for latency-critical workloads such as RTB pipelines, where you need a gate decision in under 15 ms.
1

Install the package

The package is ESM-only and requires Node.js 22 LTS or later.
2

Create an engine

Call createEngine once — typically at module initialisation — and reuse the engine for every request. Engines are stateless and safe to share across async calls.
timeout is the wall-clock budget shared across all gates. If the budget is exhausted the engine aborts remaining work and marks those gates as failed.
3

Evaluate an agent output

Call engine.evaluate() with an EvaluationContext after your agent returns a result. The call is async and resolves in the time it takes all gates to run (bounded by timeout).
4

Check the result

result.passed is true only when every gate passes (or is explicitly skipped). Inspect result.gates to see which gates blocked the output and why.
The full EvaluationResult shape:
5

Send telemetry

Instantiate PectaTelemetry with your publishable key and call telemetry.track(result) after every evaluation. The call is synchronous and non-blocking — it adds the result to an in-memory buffer and returns immediately.
Telemetry flushes automatically every 5 seconds or when 100 events accumulate. Call shutdown() before your process exits to drain any remaining buffer.
sampleRate controls the fraction of evaluations that are POSTed to the cloud. It does not affect local gate execution or which evaluations feed into reputation scoring — all evaluations are counted locally regardless of sample rate.

RTB / OpenRTB example

For programmatic advertising pipelines, use the RTB gate suite. Pass the original openRtbRequest as input and the bidder response as output, then add tmaxMs and startedAt so the tmaxGuard gate can skip downstream checks when the deadline is already exhausted.

Writing a custom gate

A gate is any object with a name string and a run function. The engine provides an AbortSignal — check it at the start of long operations to respect fail-fast and timeout behaviour.
run returns { passed: boolean, reason?: string, skipped?: boolean, details?: unknown }. The engine fills in name and latency_ms automatically.