# Redlynr n8n Trial Workflow

Try the [Redlynr](https://redlynr.com) agent guardrail API from n8n using a free trial token. No wallet, no USDC, no x402 setup required.

The Trial Workflow provides up to **30 free Redlynr `/run` calls** via a proof-of-work trial token. When the 30 calls are exhausted, the workflow will begin receiving `402 Payment Required` responses. It does not automatically switch to paid x402 calls — for continued paid use, use the separate [Paid x402 Workflow](https://redlynr.com/n8n-agent-guardrails).

---

## What you need

- An n8n instance (self-hosted or n8n Cloud — the Trial Workflow uses only standard HTTP Request nodes and has no external npm dependencies)
- A Redlynr trial token (see below)
- A `tenant_id` — any string you choose to identify your namespace

No funded wallet, USDC, or x402 configuration is required.

---

## Get your trial token

Run this script once to solve a proof-of-work challenge and receive your token:

```python
#!/usr/bin/env python3
"""Redlynr trial token helper — run once to get 30 free /run calls."""
import hashlib, itertools, string, urllib.request, json

BASE = "https://redlynr.com"

# Step 1: get a challenge
with urllib.request.urlopen(f"{BASE}/trial/challenge") as r:
    ch = json.loads(r.read())
nonce, difficulty = ch["nonce"], ch["difficulty"]
print(f"Challenge received (difficulty {difficulty})...")

# Step 2: solve it locally
chars = string.ascii_letters + string.digits
solution = None
for length in range(1, 20):
    for candidate in itertools.product(chars, repeat=length):
        s = "".join(candidate)
        if hashlib.sha256((nonce + s).encode()).hexdigest().startswith("0" * difficulty):
            solution = s
            break
    if solution:
        break
print(f"Solved.")

# Step 3: claim the token
req = urllib.request.Request(
    f"{BASE}/trial/claim",
    data=json.dumps({"nonce": nonce, "solution": solution}).encode(),
    headers={"Content-Type": "application/json"},
    method="POST"
)
with urllib.request.urlopen(req) as r:
    result = json.loads(r.read())

print(f"\nTrial token: {result['trial_token']}")
print(f"Calls granted: {result['calls_granted']} (valid for {result['expires_in_s']//3600}h)")
```

Trial tokens are valid for 24 hours and grant exactly 30 calls.

---

## Import the workflow

In n8n: **Workflows → Import from file** → select `redlynr-n8n-trial-workflow.json` (or `redlynr-n8n-starter.json` — both serve the same file).

The imported workflow will be named **Redlynr Guarded Action — Trial**.

---

## Configuration fields

All configuration is in the **Prepare Action** node (a Set node). Open it and edit these values:

| Field | Required | Description |
|---|---|---|
| `tenant_id` | Yes | Replace `YOUR_TENANT_ID` with any string that identifies your namespace. Must be registered via `POST /register` before `/run` will accept it — see [Quick start](#quick-start) below. |
| `agent_id` | Yes | Identifier for the acting agent. Default: `n8n_demo_agent`. Change if running multiple distinct agents. |
| `chain_id` | Yes | Identifier for this agent task or session. Change between separate tasks so Redlynr tracks each independently. Default: `n8n_demo_chain_001`. |
| `depth` | Yes | Nesting level. `0` = top-level orchestrator, `1` = first-generation sub-agent. Default: `0`. |
| `step_cost` | Yes | Estimated cost of this agent step in USD. Used for cost budget tracking. Default: `0.01`. |
| `chain_type` | Yes | Type of agent chain. Default: `interactive`. Other values: `batch`, `scheduled`. |

## Where to enter your trial token

The trial token goes in the **Redlynr Guardrail** node (an HTTP Request node). Open it and find the request header named `X-Trial-Token`. Replace `YOUR_TRIAL_TOKEN` with the token you received from the trial script above.

---

## Quick start

Before your first `/run` call, register your `tenant_id` (one time only):

```bash
curl -X POST https://redlynr.com/register \
  -H "Content-Type: application/json" \
  -d '{"tenant_id": "your_chosen_id"}'
```

Store the `owner_token` returned — you will need it for any future policy, pause, or audit calls. It is shown only once.

---

## Decision routing

The **Switch** node routes the workflow to one of three branches based on Redlynr's response:

**proceed** → **Protected Action**: Redlynr confirmed this step is within policy. Wire your agent's real action after the Protected Action node (or replace it). The node sets `executed: true`.

**slow_down** → **Slow Down**: The agent is approaching a limit. The node captures `decision`, `reason`, and `wait_seconds` from the response. Reasons include `step_cap_warning`, `cost_budget_warning`, and `volume_pressure`. Wire a wait step or loop back to the Redlynr Guardrail node if you want to continue after pausing.

**stop** → **Action Blocked**: A hard limit has been hit. The agent chain must halt. The node sets `executed: false` and captures `decision` and `reason`. Reasons include `step_cap_exceeded`, `cost_budget_exceeded`, `retries_exhausted`, `chain_depth_exceeded`, and `agent_paused`.

---

## Connecting your protected action

Replace the **Protected Action** Set node with the real action you want to guard — an HTTP Request, AI Agent step, database operation, or any other n8n node. Connect it to the `proceed` output of the Switch node.

The **Action Blocked** branch (stop output) and **Slow Down** branch (slow_down output) should be wired to whatever your workflow does when the action cannot proceed.

---

## After 30 calls

The Trial Workflow does not automatically switch to paid x402 calls after the 30 free calls are exhausted. When the trial budget runs out, the Redlynr Guardrail node will receive `402 Payment Required` responses, which will cause the HTTP Request node to error.

For continued paid use at $0.001 per call, download and configure the **Paid x402 Workflow** from [redlynr.com/n8n-agent-guardrails](https://redlynr.com/n8n-agent-guardrails). The Paid Workflow requires self-hosted n8n and the `ethers` npm module — it does not run on n8n Cloud.

---

## Further reading

- [Redlynr API documentation](https://redlynr.com/readme)
- [n8n integration page — Trial and Paid x402 workflows](https://redlynr.com/n8n-agent-guardrails)
- [Policy defaults and configuration reference](https://redlynr.com/readme)
