Scheduled workflows are where AI spend gets away from people: a cron trigger, a loop over a spreadsheet, a retry setting nobody remembers turning on. This post builds the guardrail from the spend control guide as an n8n workflow: get a price, stop if it is over budget, wait for a person to approve, and only then generate.
It uses plain HTTP Request nodes against the Raywake API, so it needs no community node, and it works with any of the 500+ models in the catalog: change the model ID and the input in one node.
What the workflow does
Settings holds the model ID, the input and a
max_usdceiling.Quote calls
POST /v1/quotes. The response hasquote_id,price_usdandexpires_at. No job starts and nothing is spent.Under budget? compares
price_usdwithmax_usd. Over budget ends the run.Approval request builds a message with the price and two links, approve and reject.
Wait for approval pauses the execution until one of those links is opened, for at most 9 minutes. A quote is valid for at most 10, so an approval never lands on an expired quote.
Approved? checks which link was opened. Reject or timeout ends the run.
Generate calls
POST /v1/generate?wait=truewith the same model, input andquote_id, plus anIdempotency-Key.Finished?, Wait 5 s and Get job poll
GET /v1/jobs/{job_id}until the job is finished or held. Result keeps the status,charged_usdand the output URLs.
Before you import
Create a Raywake API key with the generate and jobs:read permissions, and an expiry (Authentication). Use a separate key for this workflow, so its spending can be filtered later.
Create an n8n credential of type Header Auth:
| Field | Value |
|---|---|
| Name | Authorization |
| Value | Bearer followed by your key |
The key lives in n8n's credential store, not in the workflow JSON. After importing, select this credential on the three HTTP Request nodes (Quote, Generate, Get job).
The workflow JSON
Copy it and paste it into an empty n8n canvas, or save it as a file and use Import from File. The example prices one nano-banana-pro image at 1:1; its model page lists $0.24 per image at 1K or 2K, so the $0.50 ceiling lets it through.
{
"name": "Raywake: quote, approve, generate",
"nodes": [
{
"id": "4cc0889c-16e7-535e-a325-e08fdf3aecde",
"name": "Start",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
0,
300
],
"parameters": {}
},
{
"id": "db2308b0-4e9b-5c00-9718-3769038dc49f",
"name": "Settings",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
220,
300
],
"parameters": {
"mode": "raw",
"jsonOutput": "{\n \"model\": \"nano-banana-pro\",\n \"max_usd\": 0.5,\n \"input\": {\n \"prompt\": \"A red ceramic cup on a wooden table, soft morning light\",\n \"aspect_ratio\": \"1:1\"\n }\n}",
"options": {}
}
},
{
"id": "a8dc368b-adc1-58c6-af67-dccb6001f58f",
"name": "Quote",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
440,
300
],
"parameters": {
"method": "POST",
"url": "https://api.raywake.com/v1/quotes",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify({ model: $json.model, input: $json.input }) }}",
"options": {}
}
},
{
"id": "e8fe864c-4aa8-5272-ad45-6737de78c078",
"name": "Under budget?",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
660,
300
],
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose"
},
"conditions": [
{
"id": "d4a7326a-0d01-5263-81c1-5e878cc206a1",
"leftValue": "={{ Number($json.price_usd) }}",
"operator": {
"type": "number",
"operation": "lte"
},
"rightValue": "={{ $('Settings').item.json.max_usd }}"
}
],
"combinator": "and"
},
"options": {}
}
},
{
"id": "805a9686-e740-52f9-839b-f2861a7fbcb1",
"name": "Approval request",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
880,
200
],
"parameters": {
"mode": "raw",
"jsonOutput": "={{ JSON.stringify({\n text: `Raywake: ${$('Settings').item.json.model} costs ${$json.price_usd} USD (quote valid until ${$json.expires_at}).`,\n approve_url: $execution.resumeUrl + ($execution.resumeUrl.includes('?') ? '&' : '?') + 'decision=approve',\n reject_url: $execution.resumeUrl + ($execution.resumeUrl.includes('?') ? '&' : '?') + 'decision=reject'\n}) }}",
"options": {}
}
},
{
"id": "db0997d4-7156-5eed-a74e-1f7b09b89a26",
"name": "Wait for approval",
"type": "n8n-nodes-base.wait",
"typeVersion": 1.1,
"position": [
1100,
200
],
"webhookId": "439bbbad-82d5-550c-b134-936fc45262ef",
"parameters": {
"resume": "webhook",
"httpMethod": "GET",
"limitWaitTime": true,
"limitType": "afterTimeInterval",
"resumeAmount": 9,
"resumeUnit": "minutes",
"options": {}
}
},
{
"id": "b2a209a8-7d75-500d-970e-269eb446ea44",
"name": "Approved?",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
1320,
200
],
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose"
},
"conditions": [
{
"id": "e1726ca3-08d2-50ff-9a54-fd7c96db45ea",
"leftValue": "={{ $json.query?.decision ?? '' }}",
"operator": {
"type": "string",
"operation": "equals"
},
"rightValue": "approve"
}
],
"combinator": "and"
},
"options": {}
}
},
{
"id": "ca5be838-3d3f-53d0-bb9c-94f8070d67d5",
"name": "Generate",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1540,
100
],
"parameters": {
"method": "POST",
"url": "https://api.raywake.com/v1/generate",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "wait",
"value": "true"
}
]
},
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Idempotency-Key",
"value": "=n8n-{{ $execution.id }}"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify({ model: $('Settings').item.json.model, input: $('Settings').item.json.input, quote_id: $('Quote').item.json.quote_id }) }}",
"options": {
"timeout": 200000
}
}
},
{
"id": "cdc75dc0-1f63-578e-8b95-a8f867d71b90",
"name": "Finished?",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
1760,
100
],
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose"
},
"conditions": [
{
"id": "3a55b1b7-4840-5a6e-aed9-30c24bb22ee1",
"leftValue": "={{ [\"succeeded\", \"failed\", \"needs_review\", \"submission_unknown\", \"needs_reconciliation\"].includes($json.status) }}",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
}
},
{
"id": "de643961-48ec-5bef-a1a4-18946cef1a16",
"name": "Wait 5 s",
"type": "n8n-nodes-base.wait",
"typeVersion": 1.1,
"position": [
1980,
260
],
"webhookId": "10039c6c-9a28-5d61-9813-c49f10310b4d",
"parameters": {
"amount": 5,
"unit": "seconds"
}
},
{
"id": "6949ee2d-07fa-596e-9393-934963ec9fee",
"name": "Get job",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
2200,
260
],
"parameters": {
"method": "GET",
"url": "={{ 'https://api.raywake.com/v1/jobs/' + $json.job_id }}",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"options": {}
}
},
{
"id": "ec9e3a0b-7b88-57de-bfdd-db4d2f26f112",
"name": "Result",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1980,
40
],
"parameters": {
"mode": "raw",
"jsonOutput": "={{ JSON.stringify({ status: $json.status, charged_usd: $json.charged_usd, urls: ($json.outputs || []).map(o => o.url), error: $json.error }) }}",
"options": {}
}
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Settings",
"type": "main",
"index": 0
}
]
]
},
"Settings": {
"main": [
[
{
"node": "Quote",
"type": "main",
"index": 0
}
]
]
},
"Quote": {
"main": [
[
{
"node": "Under budget?",
"type": "main",
"index": 0
}
]
]
},
"Under budget?": {
"main": [
[
{
"node": "Approval request",
"type": "main",
"index": 0
}
]
]
},
"Approval request": {
"main": [
[
{
"node": "Wait for approval",
"type": "main",
"index": 0
}
]
]
},
"Wait for approval": {
"main": [
[
{
"node": "Approved?",
"type": "main",
"index": 0
}
]
]
},
"Approved?": {
"main": [
[
{
"node": "Generate",
"type": "main",
"index": 0
}
]
]
},
"Generate": {
"main": [
[
{
"node": "Finished?",
"type": "main",
"index": 0
}
]
]
},
"Finished?": {
"main": [
[
{
"node": "Result",
"type": "main",
"index": 0
}
],
[
{
"node": "Wait 5 s",
"type": "main",
"index": 0
}
]
]
},
"Wait 5 s": {
"main": [
[
{
"node": "Get job",
"type": "main",
"index": 0
}
]
]
},
"Get job": {
"main": [
[
{
"node": "Finished?",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"pinData": {}
}Wire up the approval message
The Approval request node outputs text, approve_url and reject_url. The URLs come from $execution.resumeUrl, which resumes this specific execution. Add whatever channel your team uses (email, Slack, Telegram, Discord) between Approval request and Wait for approval, and send those three fields. Opening the approve link resumes the workflow with ?decision=approve. Anything else, including no answer within 9 minutes, ends the run without generating.
One caution: the approve link is a plain GET. Chat apps and mail scanners that preview links can open it on their own and approve the run. Turn off link previews for that message, or send the links where nothing fetches them automatically.
If the price is always under a small ceiling and you trust it, you can delete the two approval nodes and let Under budget? be the only gate. Keep the account-level limits below either way.
The details that matter
Exact input binding. Generate sends $('Settings').item.json.input, the same object that was quoted. If anything changes the input between the two calls, Raywake answers 409 instead of running an unpriced job. Request a new quote with the final input.
Idempotent retries. The Generate node sends Idempotency-Key: n8n-{{ $execution.id }}. If you turn on n8n's Retry On Fail for that node, every retry carries the same key and body, so Raywake returns the original job instead of starting a second paid one. The same key with a different body returns 409.
A long wait is not a failure. With wait=true, the generate request returns when the job is terminal or after about three minutes. The node timeout is set to 200 seconds so n8n does not give up first. Longer jobs come back still running and the poll loop takes over. The loop stops on the terminal statuses succeeded and failed, and on the held statuses needs_review, submission_unknown and needs_reconciliation. Held jobs keep their funds reserved and can still turn into a result: route them to a person, do not resubmit. See Generations.
Usage-billed models. For models billed by seconds or characters, price_usd is an upper bound and you are charged the measured amount. The budget check against the quote is still the right check, because a generation never costs more than its quote.
Prefer webhooks to polling?
POST /v1/generate also accepts a webhook_url: a public https URL on port 443. When the job ends, Raywake POSTs a signed event (job.succeeded or job.failed) whose data is the same object GET /v1/jobs/{job_id} returns. A second workflow with an n8n Webhook trigger can receive it. Verify the webhook-id, webhook-timestamp and webhook-signature headers (Standard Webhooks) with the signing secret from the API keys page, answer with a 2xx within 10 seconds, and use webhook-id to ignore repeats. Details are in the generate reference.
Guardrails outside the workflow
Spending limits per hour or per 24 hours on the Alerts page in the studio. A generation that would cross one returns
429withX-Limit-Reason: spend_limit. Workflows cannot change these limits; only the studio can. See Errors and limits.One key per workflow. Every job records the
api_key_idthat started it.GET /v1/jobs?api_key_id=...&since=...lists that workflow's jobs withcharged_usd, andGET /v1/usage?days=7breaks spending down by day and by model. See Jobs and Usage.Not enough balance stops generation with a
402, before anything runs.
To run the same flow from Claude, Cursor or your own agent instead of n8n, start with the spend control guide. To see it on a real job, the product photo guide quotes and approves each step of a label-safe product shot.
Read the API quickstart