Set up Sealgraf in Dify
Cap the purchases in your Dify workflow, ask the owner above their approval line, and seal a receipt after a real paid action. Sealgraf checks spending permissions; your existing payment tool makes the purchase.
Connect your key
- Get a Dify key. Sign in, set Dify's limits, and copy the key. Your Dify selection stays with you through sign-in.
- In Dify, install Sealgraf, open its credentials, paste the key into Sealgraf API Key, and save. Keep the default base URL
https://sealgraf.com. - Download the first-check workflow. In Dify Studio choose Import DSL file, select the file, and select your saved credentials in Check permission.
- Run with
100minor units ($1 for a USD limit) and a category allowed by your limits. The output gives the decision, check ID, and next step. No model provider or paid tool is needed for this starter.
The starter creates a real check. An allowed check can reserve budget until it expires. It makes no payment and does not forward its decision token. Use a fresh check in your purchase workflow when you are ready to buy.
Try owner approval
Choose a sample amount above Ask me above, within Most per purchase and your remaining budget. A denied request is not an approval request; check its reason before trying another amount.
When the result is needs_human_approval, open its approval_url. Sign in as the owner, review the amount and merchant, and approve or decline. The decision stays on the owner's Sealgraf page.
Download the status workflow, import it in Dify, select the same saved credentials, and run it with the returned preauth_id. It reads the decision without creating another check. authorized means you may buy now: your limits allowed it, or the owner approved it; pending_approval, denied, aborted and expired must stop the paid action. This read never buys or seals a receipt.
Recipe: cap paid API or tool calls
Use one key per workflow so you can pause it independently and see which key is being used. Check the provider's quoted price before each paid action; an estimated amount alone cannot enforce an unknown final charge. Sealgraf cannot stop a payment tool that bypasses the check.
Wire these nodes in your existing workflow:
| Step | Dify node and wiring |
|---|---|
| Check | Check Permission with the actual category, quoted integer amount_minor, counterparty, and a stable idempotency_key of at least 8 characters for this proposed purchase. |
| Route | A Code node reads the check node's json array; an IF/ELSE node routes only allow toward the paid action. deny stops. needs_human_approval returns the check ID and approval link, then stops this run. |
| Resume approval | On a later run, use the original check ID and the same saved credentials with Claim Decision Token. A pending, declined, expired, or different-key request fails; no paid action follows an error. Extract the returned token with a Code node. |
| Pay | Run your existing paid API/tool action once, using the provider's idempotency support. Retain its real successful response, actual amount charged, and transaction reference. |
| Seal | Complete Purchase receives preauth_id, decision_token, a stable completion_nonce of at least 8 characters, completed_amount_minor from the paid response, and counterparty_receipt_ref from that response. |
| Read | Get Receipt / Check Status receives the returned receipt_id. Display the receipt ID and outcome. |
Tokens travel by variable reference between nodes. Keep them out of End outputs, prompts and messages. Dify may retain tool execution data in its run history; restrict access to that history as you would credentials.
Dify tool JSON fields need a Code node between tools. Give the Code node a result input wired to the upstream tool's json output:
def main(result: list) -> dict:
if not result or not isinstance(result[0], dict):
raise ValueError("No Sealgraf decision received")
item = result[0]
if not item.get("preauth_id") or not item.get("decision_token"):
raise ValueError("No executable authorization received")
return {"preauth_id": item["preauth_id"],
"decision_token": item["decision_token"]}
Declare both Code outputs as strings. For a first check, run this extraction only on the allow branch. After an owner approval, feed it the claim node's JSON. A replayed check may omit its token; stop and recover the original authorization rather than paying again.
Recipe: approve a paid webhook or Stripe action
Use the same sequence above, with HTTP Request or your existing Stripe action as the paid node. Set Ask me above below this action's quoted amount to require owner review. A webhook must report whether payment actually succeeded, its actual charge, and a durable purchase reference. An HTTP 200 or a Stripe Checkout Session alone does not establish a completed payment.
Do not automatically retry a paid webhook unless its contract guarantees deduplication with your stable purchase ID. If a request times out after it may have charged, reconcile with the provider before another payment. Retry receipt sealing with the same completion_nonce and evidence; do not rerun the payment node to repair a failed completion.
If payment fails, stop before Complete Purchase. Never seal a sample, a quote, a pending checkout, or a fabricated charge as a completed purchase.
Agent app instructions
For an existing Dify Agent app with a real purchase tool, add all four Sealgraf tools and use:
Before every paid action, call Check Permission with its category,
quoted amount in integer minor units, and counterparty.
If denied, stop. If waiting for owner approval, stop and show the owner
https://sealgraf.com/approve/{preauth_id}. Resume only after the owner
has decided; use Claim Decision Token with the same credentials and
original preauth_id. A failed claim is never permission to buy.
On allow, use the returned decision token internally. Execute the paid
action once with provider idempotency. After confirmed payment, call
Complete Purchase with the preauth_id, decision_token, a stable
completion_nonce (at least 8 characters), the actual amount charged,
and the provider's transaction reference. Then read back the receipt.
Never print keys or tokens. Never change limits to make a purchase fit.
Never complete a purchase that did not happen. If payment status is
uncertain, reconcile it instead of retrying the charge.
If setup stops
- Credential rejected: use the agent key for this Dify workflow, with its active limit. A saved credential confirms authentication; it is not a purchase check.
- Check denied: read the reason and category. The owner decides whether to edit limits.
- Still pending after approval: read the same check ID using the same key. A new check creates a different request.
- Completion failed after payment: preserve the provider's successful payment response and retry sealing with the same completion nonce. Do not charge again.
Want help? Reply to your requested setup check-in email, or contact support@sealgraf.com with your workflow goal and the error message. Keep your key and decision tokens private.