[{"data":1,"prerenderedAt":1436},["ShallowReactive",2],{"article-alternates":3,"article-\u002Fen\u002Fai\u002Fn8n-claude-api-autonomous-workflows":12},{"i18nKey":4,"paths":5},"ai-005-2026-06",{"de":6,"en":7,"es":8,"fr":9,"it":10,"ru":11},"\u002Fde\u002Fai\u002Fn8n-claude-api-marketing-automation-idempotency","\u002Fen\u002Fai\u002Fn8n-claude-api-autonomy-marketing-operations","\u002Fes\u002Fai\u002Fn8n-claude-api-automatizacion-operaciones-marketing","\u002Ffr\u002Fai\u002Fn8n-claude-api-autonomie-operations-marketing","\u002Fit\u002Fai\u002Fn8n-claude-api-marketing-autonomy","\u002Fru\u002Fai\u002Fn8n-claude-api-marketing-automation",{"_path":13,"_dir":14,"_draft":15,"_partial":15,"_locale":16,"title":17,"description":18,"publishedAt":19,"modifiedAt":19,"category":14,"i18nKey":4,"tags":20,"readingTime":26,"author":27,"body":28,"_type":1430,"_id":1431,"_source":1432,"_file":1433,"_stem":1434,"_extension":1435},"\u002Fen\u002Fai\u002Fn8n-claude-api-autonomous-workflows","ai",false,"","n8n + Claude API: Autonomy in Marketing Operations","Autonomous workflow design, idempotency, and error handling: how to run Claude API in production with n8n.","2026-06-25",[21,22,23,24,25],"n8n","claude-api","workflow-automation","idempotency","llm-ops",8,"Roibase",{"type":29,"children":30,"toc":1420},"root",[31,39,46,51,56,72,78,83,97,118,123,130,139,144,150,155,160,799,804,817,1023,1028,1033,1039,1044,1057,1147,1160,1173,1342,1347,1353,1358,1363,1371,1376,1389,1395,1400,1414],{"type":32,"tag":33,"props":34,"children":35},"element","p",{},[36],{"type":37,"value":38},"text","Most marketing operations consist of manual loops: you gather reports, clean data, extract insights, trigger actions. You know you can automate these loops with an LLM — but how do you reach production-grade \"set it and forget it\" reliability with n8n and Claude API? The critical step isn't writing code; it's architecting a system that can correct itself. Without idempotency, error handling, cost controls, and observability, automation becomes fragile.",{"type":32,"tag":40,"props":41,"children":43},"h2",{"id":42},"what-autonomous-workflow-actually-means",[44],{"type":37,"value":45},"What Autonomous Workflow Actually Means",{"type":32,"tag":33,"props":47,"children":48},{},[49],{"type":37,"value":50},"Autonomous workflow doesn't mean \"runs once, then breaks.\" True autonomy means the system catches its own errors, retries when hitting rate limits, and never processes the same input twice. When you trigger a Claude API node in n8n, the default behavior is simple: send HTTP request, receive response, move to next node. But in production, responses can lag, the API can return 429 (rate limit), you might get malformed JSON, or Claude might answer the same question in two different formats.",{"type":32,"tag":33,"props":52,"children":53},{},[54],{"type":37,"value":55},"This is why every node in your workflow should contain error-handling logic. n8n's error trigger mechanism enables this: when a node fails, you catch it in a separate branch, log to Slack, or send alerts via webhook to your monitoring system. An autonomous workflow is one that can self-correct without human intervention — or at least report its own state. Anthropic's API documentation recommends retry strategies (exponential backoff, 3–5 attempts) — you encode these strategies in an n8n Function node.",{"type":32,"tag":33,"props":57,"children":58},{},[59,61,70],{"type":37,"value":60},"Another critical factor: workflows grow complex over time. Three months later, understanding what each node does becomes difficult. Add \"Sticky Note\" annotations to every critical node — document which Claude prompt runs, what data structure is expected. When we optimize ",{"type":32,"tag":62,"props":63,"children":67},"a",{"href":64,"rel":65},"https:\u002F\u002Fwww.roibase.com.tr\u002Fen\u002Fverianalizi",[66],"nofollow",[68],{"type":37,"value":69},"data analytics",{"type":37,"value":71}," operations at Roibase, documenting which Claude call solves which business logic saves enormous time during refactoring months later.",{"type":32,"tag":40,"props":73,"children":75},{"id":74},"idempotency-never-do-the-same-work-twice",[76],{"type":37,"value":77},"Idempotency: Never Do the Same Work Twice",{"type":32,"tag":33,"props":79,"children":80},{},[81],{"type":37,"value":82},"Idempotency is critical in marketing operations. For example: you pull keyword data from Google Search Console (GSC), send it to Claude for analysis, and your workflow triggers daily at 08:00. One morning a network glitch interrupts it halfway; you manually restart. Did the same day run twice? Without idempotency safeguards, you generate duplicate blog posts for the same keyword — creating unintended duplicate content.",{"type":32,"tag":33,"props":84,"children":85},{},[86,88,95],{"type":37,"value":87},"The simplest idempotency mechanism: assign a unique ID to each workflow execution and record the operation. In n8n, use a \"Set\" node to capture ",{"type":32,"tag":89,"props":90,"children":92},"code",{"className":91},[],[93],{"type":37,"value":94},"{{$execution.id}}",{"type":37,"value":96}," — this produces a unique string per run. Include this ID in the metadata sent to Claude, and tag the response with it when writing to the database. If the same execution ID arrives twice, a duplicate check in your database prevents reprocessing.",{"type":32,"tag":33,"props":98,"children":99},{},[100,102,108,110,116],{"type":37,"value":101},"But an ID alone isn't enough — you also need a time window. GSC data is daily-aggregated, so fetching the same day's data twice isn't idempotency violation (the data refreshed). But \"same keyword + same date + same execution ID\" is a duplicate. Handle this in PostgreSQL with ",{"type":32,"tag":89,"props":103,"children":105},{"className":104},[],[106],{"type":37,"value":107},"ON CONFLICT",{"type":37,"value":109}," clause: ",{"type":32,"tag":89,"props":111,"children":113},{"className":112},[],[114],{"type":37,"value":115},"INSERT ... ON CONFLICT (keyword, date, execution_id) DO NOTHING",{"type":37,"value":117},". n8n's Postgres node supports this syntax.",{"type":32,"tag":33,"props":119,"children":120},{},[121],{"type":37,"value":122},"Another pattern: hash Claude's response and compare. If Claude produces identical output twice (possible due to prompt caching), a hash match flags it as duplicate. This is especially useful when optimizing your cache hit rate — Anthropic's prompt caching delivers 90% cost savings but every cache hit returns the same response, which strengthens idempotency.",{"type":32,"tag":124,"props":125,"children":127},"h3",{"id":126},"example-idempotent-workflow-structure",[128],{"type":37,"value":129},"Example: Idempotent Workflow Structure",{"type":32,"tag":131,"props":132,"children":134},"pre",{"code":133},"1. Trigger (Cron: daily 08:00)\n2. GSC API call → keyword list\n3. Loop node (for each keyword)\n   ├─ Check DB: does this keyword + today's date + execution_id exist?\n   ├─ If exists → SKIP (idempotency)\n   └─ If not → Claude API call\n       ├─ Parse response\n       ├─ Write to DB (keyword, date, execution_id, content)\n       └─ Error trigger → Slack alert\n",[135],{"type":32,"tag":89,"props":136,"children":137},{"__ignoreMap":16},[138],{"type":37,"value":133},{"type":32,"tag":33,"props":140,"children":141},{},[142],{"type":37,"value":143},"This ensures that when a 1450-word article is generated, the same keyword never processes twice on the same day. If the workflow crashes, restart only processes unhandled keywords — already-processed ones are skipped.",{"type":32,"tag":40,"props":145,"children":147},{"id":146},"error-handling-rate-limits-timeouts-malformed-output",[148],{"type":37,"value":149},"Error Handling: Rate Limits, Timeouts, Malformed Output",{"type":32,"tag":33,"props":151,"children":152},{},[153],{"type":37,"value":154},"The most common Claude API errors in production: 429 (rate limit), 503 (service unavailable), 408 (timeout), 400 (malformed request). n8n's \"HTTP Request\" node doesn't automatically catch these — you do. Default behavior: error stops the workflow. But if you want autonomy, retry instead of stopping.",{"type":32,"tag":33,"props":156,"children":157},{},[158],{"type":37,"value":159},"Implement retry logic in a Function node (JavaScript):",{"type":32,"tag":131,"props":161,"children":165},{"code":162,"language":163,"meta":16,"className":164,"style":16},"const maxRetries = 3;\nlet retries = 0;\nlet response;\n\nwhile (retries \u003C maxRetries) {\n  try {\n    response = await fetch('https:\u002F\u002Fapi.anthropic.com\u002Fv1\u002Fmessages', {\n      method: 'POST',\n      headers: { \u002F* ... *\u002F },\n      body: JSON.stringify({ \u002F* ... *\u002F })\n    });\n    \n    if (response.status === 429) {\n      \u002F\u002F Exponential backoff: 2^retries seconds\n      await new Promise(r => setTimeout(r, Math.pow(2, retries) * 1000));\n      retries++;\n      continue;\n    }\n    \n    if (response.ok) break;\n    \n    throw new Error(`HTTP ${response.status}`);\n  } catch (err) {\n    retries++;\n    if (retries >= maxRetries) throw err;\n  }\n}\n\nreturn { json: await response.json() };\n","javascript","language-javascript shiki shiki-themes github-dark",[166],{"type":32,"tag":89,"props":167,"children":168},{"__ignoreMap":16},[169,203,231,244,254,278,292,332,350,370,408,417,426,455,464,542,560,573,582,590,612,620,671,690,707,739,748,757,765],{"type":32,"tag":170,"props":171,"children":174},"span",{"class":172,"line":173},"line",1,[175,181,187,192,197],{"type":32,"tag":170,"props":176,"children":178},{"style":177},"--shiki-default:#F97583",[179],{"type":37,"value":180},"const",{"type":32,"tag":170,"props":182,"children":184},{"style":183},"--shiki-default:#79B8FF",[185],{"type":37,"value":186}," maxRetries",{"type":32,"tag":170,"props":188,"children":189},{"style":177},[190],{"type":37,"value":191}," =",{"type":32,"tag":170,"props":193,"children":194},{"style":183},[195],{"type":37,"value":196}," 3",{"type":32,"tag":170,"props":198,"children":200},{"style":199},"--shiki-default:#E1E4E8",[201],{"type":37,"value":202},";\n",{"type":32,"tag":170,"props":204,"children":206},{"class":172,"line":205},2,[207,212,217,222,227],{"type":32,"tag":170,"props":208,"children":209},{"style":177},[210],{"type":37,"value":211},"let",{"type":32,"tag":170,"props":213,"children":214},{"style":199},[215],{"type":37,"value":216}," retries ",{"type":32,"tag":170,"props":218,"children":219},{"style":177},[220],{"type":37,"value":221},"=",{"type":32,"tag":170,"props":223,"children":224},{"style":183},[225],{"type":37,"value":226}," 0",{"type":32,"tag":170,"props":228,"children":229},{"style":199},[230],{"type":37,"value":202},{"type":32,"tag":170,"props":232,"children":234},{"class":172,"line":233},3,[235,239],{"type":32,"tag":170,"props":236,"children":237},{"style":177},[238],{"type":37,"value":211},{"type":32,"tag":170,"props":240,"children":241},{"style":199},[242],{"type":37,"value":243}," response;\n",{"type":32,"tag":170,"props":245,"children":247},{"class":172,"line":246},4,[248],{"type":32,"tag":170,"props":249,"children":251},{"emptyLinePlaceholder":250},true,[252],{"type":37,"value":253},"\n",{"type":32,"tag":170,"props":255,"children":257},{"class":172,"line":256},5,[258,263,268,273],{"type":32,"tag":170,"props":259,"children":260},{"style":177},[261],{"type":37,"value":262},"while",{"type":32,"tag":170,"props":264,"children":265},{"style":199},[266],{"type":37,"value":267}," (retries ",{"type":32,"tag":170,"props":269,"children":270},{"style":177},[271],{"type":37,"value":272},"\u003C",{"type":32,"tag":170,"props":274,"children":275},{"style":199},[276],{"type":37,"value":277}," maxRetries) {\n",{"type":32,"tag":170,"props":279,"children":281},{"class":172,"line":280},6,[282,287],{"type":32,"tag":170,"props":283,"children":284},{"style":177},[285],{"type":37,"value":286},"  try",{"type":32,"tag":170,"props":288,"children":289},{"style":199},[290],{"type":37,"value":291}," {\n",{"type":32,"tag":170,"props":293,"children":295},{"class":172,"line":294},7,[296,301,305,310,316,321,327],{"type":32,"tag":170,"props":297,"children":298},{"style":199},[299],{"type":37,"value":300},"    response ",{"type":32,"tag":170,"props":302,"children":303},{"style":177},[304],{"type":37,"value":221},{"type":32,"tag":170,"props":306,"children":307},{"style":177},[308],{"type":37,"value":309}," await",{"type":32,"tag":170,"props":311,"children":313},{"style":312},"--shiki-default:#B392F0",[314],{"type":37,"value":315}," fetch",{"type":32,"tag":170,"props":317,"children":318},{"style":199},[319],{"type":37,"value":320},"(",{"type":32,"tag":170,"props":322,"children":324},{"style":323},"--shiki-default:#9ECBFF",[325],{"type":37,"value":326},"'https:\u002F\u002Fapi.anthropic.com\u002Fv1\u002Fmessages'",{"type":32,"tag":170,"props":328,"children":329},{"style":199},[330],{"type":37,"value":331},", {\n",{"type":32,"tag":170,"props":333,"children":334},{"class":172,"line":26},[335,340,345],{"type":32,"tag":170,"props":336,"children":337},{"style":199},[338],{"type":37,"value":339},"      method: ",{"type":32,"tag":170,"props":341,"children":342},{"style":323},[343],{"type":37,"value":344},"'POST'",{"type":32,"tag":170,"props":346,"children":347},{"style":199},[348],{"type":37,"value":349},",\n",{"type":32,"tag":170,"props":351,"children":353},{"class":172,"line":352},9,[354,359,365],{"type":32,"tag":170,"props":355,"children":356},{"style":199},[357],{"type":37,"value":358},"      headers: { ",{"type":32,"tag":170,"props":360,"children":362},{"style":361},"--shiki-default:#6A737D",[363],{"type":37,"value":364},"\u002F* ... *\u002F",{"type":32,"tag":170,"props":366,"children":367},{"style":199},[368],{"type":37,"value":369}," },\n",{"type":32,"tag":170,"props":371,"children":373},{"class":172,"line":372},10,[374,379,384,389,394,399,403],{"type":32,"tag":170,"props":375,"children":376},{"style":199},[377],{"type":37,"value":378},"      body: ",{"type":32,"tag":170,"props":380,"children":381},{"style":183},[382],{"type":37,"value":383},"JSON",{"type":32,"tag":170,"props":385,"children":386},{"style":199},[387],{"type":37,"value":388},".",{"type":32,"tag":170,"props":390,"children":391},{"style":312},[392],{"type":37,"value":393},"stringify",{"type":32,"tag":170,"props":395,"children":396},{"style":199},[397],{"type":37,"value":398},"({ ",{"type":32,"tag":170,"props":400,"children":401},{"style":361},[402],{"type":37,"value":364},{"type":32,"tag":170,"props":404,"children":405},{"style":199},[406],{"type":37,"value":407}," })\n",{"type":32,"tag":170,"props":409,"children":411},{"class":172,"line":410},11,[412],{"type":32,"tag":170,"props":413,"children":414},{"style":199},[415],{"type":37,"value":416},"    });\n",{"type":32,"tag":170,"props":418,"children":420},{"class":172,"line":419},12,[421],{"type":32,"tag":170,"props":422,"children":423},{"style":199},[424],{"type":37,"value":425},"    \n",{"type":32,"tag":170,"props":427,"children":429},{"class":172,"line":428},13,[430,435,440,445,450],{"type":32,"tag":170,"props":431,"children":432},{"style":177},[433],{"type":37,"value":434},"    if",{"type":32,"tag":170,"props":436,"children":437},{"style":199},[438],{"type":37,"value":439}," (response.status ",{"type":32,"tag":170,"props":441,"children":442},{"style":177},[443],{"type":37,"value":444},"===",{"type":32,"tag":170,"props":446,"children":447},{"style":183},[448],{"type":37,"value":449}," 429",{"type":32,"tag":170,"props":451,"children":452},{"style":199},[453],{"type":37,"value":454},") {\n",{"type":32,"tag":170,"props":456,"children":458},{"class":172,"line":457},14,[459],{"type":32,"tag":170,"props":460,"children":461},{"style":361},[462],{"type":37,"value":463},"      \u002F\u002F Exponential backoff: 2^retries seconds\n",{"type":32,"tag":170,"props":465,"children":467},{"class":172,"line":466},15,[468,473,478,483,487,493,498,503,508,513,517,522,527,532,537],{"type":32,"tag":170,"props":469,"children":470},{"style":177},[471],{"type":37,"value":472},"      await",{"type":32,"tag":170,"props":474,"children":475},{"style":177},[476],{"type":37,"value":477}," new",{"type":32,"tag":170,"props":479,"children":480},{"style":183},[481],{"type":37,"value":482}," Promise",{"type":32,"tag":170,"props":484,"children":485},{"style":199},[486],{"type":37,"value":320},{"type":32,"tag":170,"props":488,"children":490},{"style":489},"--shiki-default:#FFAB70",[491],{"type":37,"value":492},"r",{"type":32,"tag":170,"props":494,"children":495},{"style":177},[496],{"type":37,"value":497}," =>",{"type":32,"tag":170,"props":499,"children":500},{"style":312},[501],{"type":37,"value":502}," setTimeout",{"type":32,"tag":170,"props":504,"children":505},{"style":199},[506],{"type":37,"value":507},"(r, Math.",{"type":32,"tag":170,"props":509,"children":510},{"style":312},[511],{"type":37,"value":512},"pow",{"type":32,"tag":170,"props":514,"children":515},{"style":199},[516],{"type":37,"value":320},{"type":32,"tag":170,"props":518,"children":519},{"style":183},[520],{"type":37,"value":521},"2",{"type":32,"tag":170,"props":523,"children":524},{"style":199},[525],{"type":37,"value":526},", retries) ",{"type":32,"tag":170,"props":528,"children":529},{"style":177},[530],{"type":37,"value":531},"*",{"type":32,"tag":170,"props":533,"children":534},{"style":183},[535],{"type":37,"value":536}," 1000",{"type":32,"tag":170,"props":538,"children":539},{"style":199},[540],{"type":37,"value":541},"));\n",{"type":32,"tag":170,"props":543,"children":545},{"class":172,"line":544},16,[546,551,556],{"type":32,"tag":170,"props":547,"children":548},{"style":199},[549],{"type":37,"value":550},"      retries",{"type":32,"tag":170,"props":552,"children":553},{"style":177},[554],{"type":37,"value":555},"++",{"type":32,"tag":170,"props":557,"children":558},{"style":199},[559],{"type":37,"value":202},{"type":32,"tag":170,"props":561,"children":563},{"class":172,"line":562},17,[564,569],{"type":32,"tag":170,"props":565,"children":566},{"style":177},[567],{"type":37,"value":568},"      continue",{"type":32,"tag":170,"props":570,"children":571},{"style":199},[572],{"type":37,"value":202},{"type":32,"tag":170,"props":574,"children":576},{"class":172,"line":575},18,[577],{"type":32,"tag":170,"props":578,"children":579},{"style":199},[580],{"type":37,"value":581},"    }\n",{"type":32,"tag":170,"props":583,"children":585},{"class":172,"line":584},19,[586],{"type":32,"tag":170,"props":587,"children":588},{"style":199},[589],{"type":37,"value":425},{"type":32,"tag":170,"props":591,"children":593},{"class":172,"line":592},20,[594,598,603,608],{"type":32,"tag":170,"props":595,"children":596},{"style":177},[597],{"type":37,"value":434},{"type":32,"tag":170,"props":599,"children":600},{"style":199},[601],{"type":37,"value":602}," (response.ok) ",{"type":32,"tag":170,"props":604,"children":605},{"style":177},[606],{"type":37,"value":607},"break",{"type":32,"tag":170,"props":609,"children":610},{"style":199},[611],{"type":37,"value":202},{"type":32,"tag":170,"props":613,"children":615},{"class":172,"line":614},21,[616],{"type":32,"tag":170,"props":617,"children":618},{"style":199},[619],{"type":37,"value":425},{"type":32,"tag":170,"props":621,"children":623},{"class":172,"line":622},22,[624,629,633,638,642,647,652,656,661,666],{"type":32,"tag":170,"props":625,"children":626},{"style":177},[627],{"type":37,"value":628},"    throw",{"type":32,"tag":170,"props":630,"children":631},{"style":177},[632],{"type":37,"value":477},{"type":32,"tag":170,"props":634,"children":635},{"style":312},[636],{"type":37,"value":637}," Error",{"type":32,"tag":170,"props":639,"children":640},{"style":199},[641],{"type":37,"value":320},{"type":32,"tag":170,"props":643,"children":644},{"style":323},[645],{"type":37,"value":646},"`HTTP ${",{"type":32,"tag":170,"props":648,"children":649},{"style":199},[650],{"type":37,"value":651},"response",{"type":32,"tag":170,"props":653,"children":654},{"style":323},[655],{"type":37,"value":388},{"type":32,"tag":170,"props":657,"children":658},{"style":199},[659],{"type":37,"value":660},"status",{"type":32,"tag":170,"props":662,"children":663},{"style":323},[664],{"type":37,"value":665},"}`",{"type":32,"tag":170,"props":667,"children":668},{"style":199},[669],{"type":37,"value":670},");\n",{"type":32,"tag":170,"props":672,"children":674},{"class":172,"line":673},23,[675,680,685],{"type":32,"tag":170,"props":676,"children":677},{"style":199},[678],{"type":37,"value":679},"  } ",{"type":32,"tag":170,"props":681,"children":682},{"style":177},[683],{"type":37,"value":684},"catch",{"type":32,"tag":170,"props":686,"children":687},{"style":199},[688],{"type":37,"value":689}," (err) {\n",{"type":32,"tag":170,"props":691,"children":693},{"class":172,"line":692},24,[694,699,703],{"type":32,"tag":170,"props":695,"children":696},{"style":199},[697],{"type":37,"value":698},"    retries",{"type":32,"tag":170,"props":700,"children":701},{"style":177},[702],{"type":37,"value":555},{"type":32,"tag":170,"props":704,"children":705},{"style":199},[706],{"type":37,"value":202},{"type":32,"tag":170,"props":708,"children":710},{"class":172,"line":709},25,[711,715,719,724,729,734],{"type":32,"tag":170,"props":712,"children":713},{"style":177},[714],{"type":37,"value":434},{"type":32,"tag":170,"props":716,"children":717},{"style":199},[718],{"type":37,"value":267},{"type":32,"tag":170,"props":720,"children":721},{"style":177},[722],{"type":37,"value":723},">=",{"type":32,"tag":170,"props":725,"children":726},{"style":199},[727],{"type":37,"value":728}," maxRetries) ",{"type":32,"tag":170,"props":730,"children":731},{"style":177},[732],{"type":37,"value":733},"throw",{"type":32,"tag":170,"props":735,"children":736},{"style":199},[737],{"type":37,"value":738}," err;\n",{"type":32,"tag":170,"props":740,"children":742},{"class":172,"line":741},26,[743],{"type":32,"tag":170,"props":744,"children":745},{"style":199},[746],{"type":37,"value":747},"  }\n",{"type":32,"tag":170,"props":749,"children":751},{"class":172,"line":750},27,[752],{"type":32,"tag":170,"props":753,"children":754},{"style":199},[755],{"type":37,"value":756},"}\n",{"type":32,"tag":170,"props":758,"children":760},{"class":172,"line":759},28,[761],{"type":32,"tag":170,"props":762,"children":763},{"emptyLinePlaceholder":250},[764],{"type":37,"value":253},{"type":32,"tag":170,"props":766,"children":768},{"class":172,"line":767},29,[769,774,779,784,789,794],{"type":32,"tag":170,"props":770,"children":771},{"style":177},[772],{"type":37,"value":773},"return",{"type":32,"tag":170,"props":775,"children":776},{"style":199},[777],{"type":37,"value":778}," { json: ",{"type":32,"tag":170,"props":780,"children":781},{"style":177},[782],{"type":37,"value":783},"await",{"type":32,"tag":170,"props":785,"children":786},{"style":199},[787],{"type":37,"value":788}," response.",{"type":32,"tag":170,"props":790,"children":791},{"style":312},[792],{"type":37,"value":793},"json",{"type":32,"tag":170,"props":795,"children":796},{"style":199},[797],{"type":37,"value":798},"() };\n",{"type":32,"tag":33,"props":800,"children":801},{},[802],{"type":37,"value":803},"When receiving 429, this waits 2 seconds, then 4, then 8 — exponential backoff as recommended by Anthropic. n8n's Function node always supports JavaScript runtime, so you can use async\u002Fawait.",{"type":32,"tag":33,"props":805,"children":806},{},[807,809,815],{"type":37,"value":808},"Another common error: Claude returns malformed JSON. Especially if you force JSON output (instructing Claude to \"respond in JSON format\"), it sometimes wraps the output in markdown fences (",{"type":32,"tag":89,"props":810,"children":812},{"className":811},[],[813],{"type":37,"value":814},"```json ... ```",{"type":37,"value":816},"). You can't parse this. Solution: clean the response with regex:",{"type":32,"tag":131,"props":818,"children":820},{"code":819,"language":163,"meta":16,"className":164,"style":16},"let rawText = $json.content[0].text; \u002F\u002F Claude's raw response\nrawText = rawText.replace(\u002F```json\\n?\u002Fg, '').replace(\u002F```\\n?\u002Fg, '');\nconst parsed = JSON.parse(rawText);\nreturn { json: parsed };\n",[821],{"type":32,"tag":89,"props":822,"children":823},{"__ignoreMap":16},[824,860,976,1011],{"type":32,"tag":170,"props":825,"children":826},{"class":172,"line":173},[827,831,836,840,845,850,855],{"type":32,"tag":170,"props":828,"children":829},{"style":177},[830],{"type":37,"value":211},{"type":32,"tag":170,"props":832,"children":833},{"style":199},[834],{"type":37,"value":835}," rawText ",{"type":32,"tag":170,"props":837,"children":838},{"style":177},[839],{"type":37,"value":221},{"type":32,"tag":170,"props":841,"children":842},{"style":199},[843],{"type":37,"value":844}," $json.content[",{"type":32,"tag":170,"props":846,"children":847},{"style":183},[848],{"type":37,"value":849},"0",{"type":32,"tag":170,"props":851,"children":852},{"style":199},[853],{"type":37,"value":854},"].text; ",{"type":32,"tag":170,"props":856,"children":857},{"style":361},[858],{"type":37,"value":859},"\u002F\u002F Claude's raw response\n",{"type":32,"tag":170,"props":861,"children":862},{"class":172,"line":205},[863,868,872,877,882,886,891,897,902,907,911,916,921,926,931,935,939,943,948,952,956,960,964,968,972],{"type":32,"tag":170,"props":864,"children":865},{"style":199},[866],{"type":37,"value":867},"rawText ",{"type":32,"tag":170,"props":869,"children":870},{"style":177},[871],{"type":37,"value":221},{"type":32,"tag":170,"props":873,"children":874},{"style":199},[875],{"type":37,"value":876}," rawText.",{"type":32,"tag":170,"props":878,"children":879},{"style":312},[880],{"type":37,"value":881},"replace",{"type":32,"tag":170,"props":883,"children":884},{"style":199},[885],{"type":37,"value":320},{"type":32,"tag":170,"props":887,"children":888},{"style":323},[889],{"type":37,"value":890},"\u002F",{"type":32,"tag":170,"props":892,"children":894},{"style":893},"--shiki-default:#DBEDFF",[895],{"type":37,"value":896},"```json",{"type":32,"tag":170,"props":898,"children":899},{"style":183},[900],{"type":37,"value":901},"\\n",{"type":32,"tag":170,"props":903,"children":904},{"style":177},[905],{"type":37,"value":906},"?",{"type":32,"tag":170,"props":908,"children":909},{"style":323},[910],{"type":37,"value":890},{"type":32,"tag":170,"props":912,"children":913},{"style":177},[914],{"type":37,"value":915},"g",{"type":32,"tag":170,"props":917,"children":918},{"style":199},[919],{"type":37,"value":920},", ",{"type":32,"tag":170,"props":922,"children":923},{"style":323},[924],{"type":37,"value":925},"''",{"type":32,"tag":170,"props":927,"children":928},{"style":199},[929],{"type":37,"value":930},").",{"type":32,"tag":170,"props":932,"children":933},{"style":312},[934],{"type":37,"value":881},{"type":32,"tag":170,"props":936,"children":937},{"style":199},[938],{"type":37,"value":320},{"type":32,"tag":170,"props":940,"children":941},{"style":323},[942],{"type":37,"value":890},{"type":32,"tag":170,"props":944,"children":945},{"style":893},[946],{"type":37,"value":947},"```",{"type":32,"tag":170,"props":949,"children":950},{"style":183},[951],{"type":37,"value":901},{"type":32,"tag":170,"props":953,"children":954},{"style":177},[955],{"type":37,"value":906},{"type":32,"tag":170,"props":957,"children":958},{"style":323},[959],{"type":37,"value":890},{"type":32,"tag":170,"props":961,"children":962},{"style":177},[963],{"type":37,"value":915},{"type":32,"tag":170,"props":965,"children":966},{"style":199},[967],{"type":37,"value":920},{"type":32,"tag":170,"props":969,"children":970},{"style":323},[971],{"type":37,"value":925},{"type":32,"tag":170,"props":973,"children":974},{"style":199},[975],{"type":37,"value":670},{"type":32,"tag":170,"props":977,"children":978},{"class":172,"line":233},[979,983,988,992,997,1001,1006],{"type":32,"tag":170,"props":980,"children":981},{"style":177},[982],{"type":37,"value":180},{"type":32,"tag":170,"props":984,"children":985},{"style":183},[986],{"type":37,"value":987}," parsed",{"type":32,"tag":170,"props":989,"children":990},{"style":177},[991],{"type":37,"value":191},{"type":32,"tag":170,"props":993,"children":994},{"style":183},[995],{"type":37,"value":996}," JSON",{"type":32,"tag":170,"props":998,"children":999},{"style":199},[1000],{"type":37,"value":388},{"type":32,"tag":170,"props":1002,"children":1003},{"style":312},[1004],{"type":37,"value":1005},"parse",{"type":32,"tag":170,"props":1007,"children":1008},{"style":199},[1009],{"type":37,"value":1010},"(rawText);\n",{"type":32,"tag":170,"props":1012,"children":1013},{"class":172,"line":246},[1014,1018],{"type":32,"tag":170,"props":1015,"children":1016},{"style":177},[1017],{"type":37,"value":773},{"type":32,"tag":170,"props":1019,"children":1020},{"style":199},[1021],{"type":37,"value":1022}," { json: parsed };\n",{"type":32,"tag":33,"props":1024,"children":1025},{},[1026],{"type":37,"value":1027},"Apply this pattern after every Claude call — it reduces malformed output risk by ~80%.",{"type":32,"tag":33,"props":1029,"children":1030},{},[1031],{"type":37,"value":1032},"Finally, timeouts. Claude's response time depends on prompt complexity — a 200-token prompt typically returns in 2–3 seconds, a 2000-token prompt may take 15–20 seconds. n8n's HTTP node default timeout is 300 seconds (5 minutes) — for production, set it to 30 seconds. If exceeded, trigger a fallback strategy (shorten the prompt and retry, or pull an answer from cache).",{"type":32,"tag":40,"props":1034,"children":1036},{"id":1035},"cost-control-token-budget-and-prompt-caching",[1037],{"type":37,"value":1038},"Cost Control: Token Budget and Prompt Caching",{"type":32,"tag":33,"props":1040,"children":1041},{},[1042],{"type":37,"value":1043},"Claude API costs depend on token count: input tokens (your message) + output tokens (Claude's response) are billed together. Haiku ($0.25 \u002F 1M input tokens, $1.25 \u002F 1M output tokens — 2026 pricing) is cost-efficient; Sonnet\u002FOpus cost more. To control costs in your n8n workflow, use two mechanisms: token budget and prompt caching.",{"type":32,"tag":33,"props":1045,"children":1046},{},[1047,1049,1055],{"type":37,"value":1048},"Token budget: cap maximum tokens per workflow execution. For example, if you analyze 1000 keywords daily, expecting ~500 input + 1500 output tokens per keyword (2000 total), that's 1000 × 2000 = 2M tokens\u002Fday = ~$2.50\u002Fday with Haiku. But if Claude generates 10,000 tokens for one keyword, your budget breaks. Send Claude a ",{"type":32,"tag":89,"props":1050,"children":1052},{"className":1051},[],[1053],{"type":37,"value":1054},"max_tokens",{"type":37,"value":1056}," parameter:",{"type":32,"tag":131,"props":1058,"children":1061},{"code":1059,"language":793,"meta":16,"className":1060,"style":16},"{\n  \"model\": \"claude-3-5-haiku-20241022\",\n  \"max_tokens\": 1500,\n  \"messages\": [...]\n}\n","language-json shiki shiki-themes github-dark",[1062],{"type":32,"tag":89,"props":1063,"children":1064},{"__ignoreMap":16},[1065,1073,1095,1116,1140],{"type":32,"tag":170,"props":1066,"children":1067},{"class":172,"line":173},[1068],{"type":32,"tag":170,"props":1069,"children":1070},{"style":199},[1071],{"type":37,"value":1072},"{\n",{"type":32,"tag":170,"props":1074,"children":1075},{"class":172,"line":205},[1076,1081,1086,1091],{"type":32,"tag":170,"props":1077,"children":1078},{"style":183},[1079],{"type":37,"value":1080},"  \"model\"",{"type":32,"tag":170,"props":1082,"children":1083},{"style":199},[1084],{"type":37,"value":1085},": ",{"type":32,"tag":170,"props":1087,"children":1088},{"style":323},[1089],{"type":37,"value":1090},"\"claude-3-5-haiku-20241022\"",{"type":32,"tag":170,"props":1092,"children":1093},{"style":199},[1094],{"type":37,"value":349},{"type":32,"tag":170,"props":1096,"children":1097},{"class":172,"line":233},[1098,1103,1107,1112],{"type":32,"tag":170,"props":1099,"children":1100},{"style":183},[1101],{"type":37,"value":1102},"  \"max_tokens\"",{"type":32,"tag":170,"props":1104,"children":1105},{"style":199},[1106],{"type":37,"value":1085},{"type":32,"tag":170,"props":1108,"children":1109},{"style":183},[1110],{"type":37,"value":1111},"1500",{"type":32,"tag":170,"props":1113,"children":1114},{"style":199},[1115],{"type":37,"value":349},{"type":32,"tag":170,"props":1117,"children":1118},{"class":172,"line":246},[1119,1124,1129,1135],{"type":32,"tag":170,"props":1120,"children":1121},{"style":183},[1122],{"type":37,"value":1123},"  \"messages\"",{"type":32,"tag":170,"props":1125,"children":1126},{"style":199},[1127],{"type":37,"value":1128},": [",{"type":32,"tag":170,"props":1130,"children":1132},{"style":1131},"--shiki-default:#FDAEB7;--shiki-default-font-style:italic",[1133],{"type":37,"value":1134},"...",{"type":32,"tag":170,"props":1136,"children":1137},{"style":199},[1138],{"type":37,"value":1139},"]\n",{"type":32,"tag":170,"props":1141,"children":1142},{"class":172,"line":256},[1143],{"type":32,"tag":170,"props":1144,"children":1145},{"style":199},[1146],{"type":37,"value":756},{"type":32,"tag":33,"props":1148,"children":1149},{},[1150,1152,1158],{"type":37,"value":1151},"This guarantees Claude never exceeds 1500 output tokens. If it must truncate the answer (",{"type":32,"tag":89,"props":1153,"children":1155},{"className":1154},[],[1156],{"type":37,"value":1157},"stop_reason: \"max_tokens\"",{"type":37,"value":1159},"), you can catch and retry — though usually unnecessary. 1500 tokens ≈ 1200 words, sufficient for analysis.",{"type":32,"tag":33,"props":1161,"children":1162},{},[1163,1165,1171],{"type":37,"value":1164},"Prompt caching cuts costs by ~90%. Anthropic's mechanism works like this: reuse the same system prompt, and only changed tokens get billed. For instance, a 2000-token master prompt (like documentation) stays the same across keywords. Cache hit rate reaches ~95% — each call costs 100 input tokens instead of 2000. Enable caching in n8n by storing the system prompt on GitHub, fetching via raw URL per call, and adding ",{"type":32,"tag":89,"props":1166,"children":1168},{"className":1167},[],[1169],{"type":37,"value":1170},"cache_control",{"type":37,"value":1172},":",{"type":32,"tag":131,"props":1174,"children":1176},{"code":1175,"language":793,"meta":16,"className":1060,"style":16},"{\n  \"model\": \"claude-3-5-sonnet-20241022\",\n  \"system\": [\n    {\n      \"type\": \"text\",\n      \"text\": \"{{$json.masterPrompt}}\",\n      \"cache_control\": {\"type\": \"ephemeral\"}\n    }\n  ],\n  \"messages\": [...]\n}\n",[1177],{"type":32,"tag":89,"props":1178,"children":1179},{"__ignoreMap":16},[1180,1187,1207,1220,1228,1249,1270,1301,1308,1316,1335],{"type":32,"tag":170,"props":1181,"children":1182},{"class":172,"line":173},[1183],{"type":32,"tag":170,"props":1184,"children":1185},{"style":199},[1186],{"type":37,"value":1072},{"type":32,"tag":170,"props":1188,"children":1189},{"class":172,"line":205},[1190,1194,1198,1203],{"type":32,"tag":170,"props":1191,"children":1192},{"style":183},[1193],{"type":37,"value":1080},{"type":32,"tag":170,"props":1195,"children":1196},{"style":199},[1197],{"type":37,"value":1085},{"type":32,"tag":170,"props":1199,"children":1200},{"style":323},[1201],{"type":37,"value":1202},"\"claude-3-5-sonnet-20241022\"",{"type":32,"tag":170,"props":1204,"children":1205},{"style":199},[1206],{"type":37,"value":349},{"type":32,"tag":170,"props":1208,"children":1209},{"class":172,"line":233},[1210,1215],{"type":32,"tag":170,"props":1211,"children":1212},{"style":183},[1213],{"type":37,"value":1214},"  \"system\"",{"type":32,"tag":170,"props":1216,"children":1217},{"style":199},[1218],{"type":37,"value":1219},": [\n",{"type":32,"tag":170,"props":1221,"children":1222},{"class":172,"line":246},[1223],{"type":32,"tag":170,"props":1224,"children":1225},{"style":199},[1226],{"type":37,"value":1227},"    {\n",{"type":32,"tag":170,"props":1229,"children":1230},{"class":172,"line":256},[1231,1236,1240,1245],{"type":32,"tag":170,"props":1232,"children":1233},{"style":183},[1234],{"type":37,"value":1235},"      \"type\"",{"type":32,"tag":170,"props":1237,"children":1238},{"style":199},[1239],{"type":37,"value":1085},{"type":32,"tag":170,"props":1241,"children":1242},{"style":323},[1243],{"type":37,"value":1244},"\"text\"",{"type":32,"tag":170,"props":1246,"children":1247},{"style":199},[1248],{"type":37,"value":349},{"type":32,"tag":170,"props":1250,"children":1251},{"class":172,"line":280},[1252,1257,1261,1266],{"type":32,"tag":170,"props":1253,"children":1254},{"style":183},[1255],{"type":37,"value":1256},"      \"text\"",{"type":32,"tag":170,"props":1258,"children":1259},{"style":199},[1260],{"type":37,"value":1085},{"type":32,"tag":170,"props":1262,"children":1263},{"style":323},[1264],{"type":37,"value":1265},"\"{{$json.masterPrompt}}\"",{"type":32,"tag":170,"props":1267,"children":1268},{"style":199},[1269],{"type":37,"value":349},{"type":32,"tag":170,"props":1271,"children":1272},{"class":172,"line":294},[1273,1278,1283,1288,1292,1297],{"type":32,"tag":170,"props":1274,"children":1275},{"style":183},[1276],{"type":37,"value":1277},"      \"cache_control\"",{"type":32,"tag":170,"props":1279,"children":1280},{"style":199},[1281],{"type":37,"value":1282},": {",{"type":32,"tag":170,"props":1284,"children":1285},{"style":183},[1286],{"type":37,"value":1287},"\"type\"",{"type":32,"tag":170,"props":1289,"children":1290},{"style":199},[1291],{"type":37,"value":1085},{"type":32,"tag":170,"props":1293,"children":1294},{"style":323},[1295],{"type":37,"value":1296},"\"ephemeral\"",{"type":32,"tag":170,"props":1298,"children":1299},{"style":199},[1300],{"type":37,"value":756},{"type":32,"tag":170,"props":1302,"children":1303},{"class":172,"line":26},[1304],{"type":32,"tag":170,"props":1305,"children":1306},{"style":199},[1307],{"type":37,"value":581},{"type":32,"tag":170,"props":1309,"children":1310},{"class":172,"line":352},[1311],{"type":32,"tag":170,"props":1312,"children":1313},{"style":199},[1314],{"type":37,"value":1315},"  ],\n",{"type":32,"tag":170,"props":1317,"children":1318},{"class":172,"line":372},[1319,1323,1327,1331],{"type":32,"tag":170,"props":1320,"children":1321},{"style":183},[1322],{"type":37,"value":1123},{"type":32,"tag":170,"props":1324,"children":1325},{"style":199},[1326],{"type":37,"value":1128},{"type":32,"tag":170,"props":1328,"children":1329},{"style":1131},[1330],{"type":37,"value":1134},{"type":32,"tag":170,"props":1332,"children":1333},{"style":199},[1334],{"type":37,"value":1139},{"type":32,"tag":170,"props":1336,"children":1337},{"class":172,"line":410},[1338],{"type":32,"tag":170,"props":1339,"children":1340},{"style":199},[1341],{"type":37,"value":756},{"type":32,"tag":33,"props":1343,"children":1344},{},[1345],{"type":37,"value":1346},"This is the pattern we use at Roibase for blog generation. A 5000-token master prompt costs 5000 tokens on the first call, then ~50 tokens for each of 99 subsequent calls (only the keyword changes). For 3000 articles monthly: without caching, 15M tokens ($3.75); with caching, 450K tokens ($1.12) — 70% savings.",{"type":32,"tag":40,"props":1348,"children":1350},{"id":1349},"observability-monitoring-your-workflow",[1351],{"type":37,"value":1352},"Observability: Monitoring Your Workflow",{"type":32,"tag":33,"props":1354,"children":1355},{},[1356],{"type":37,"value":1357},"Once you build an autonomous system, \"is it running?\" isn't enough — you need to know \"where is it slow, where does it fail, how long does each node take?\" n8n's built-in execution logs exist but are insufficient. You want to track each node's latency, Claude's response time, error rates. Use an external observability tool (Datadog, Grafana, Prometheus) and push metrics from your workflow.",{"type":32,"tag":33,"props":1359,"children":1360},{},[1361],{"type":37,"value":1362},"Simple pattern: after each critical node, add an \"HTTP Request\" node that sends metrics to a Prometheus pushgateway. Example metrics:",{"type":32,"tag":131,"props":1364,"children":1366},{"code":1365},"# Claude API call latency (milliseconds)\nclaude_api_latency_ms{workflow=\"blog_generator\", model=\"haiku\"} 2340\n\n# Token usage (input + output)\nclaude_token_usage{workflow=\"blog_generator\", type=\"input\"} 450\nclaude_token_usage{workflow=\"blog_generator\", type=\"output\"} 1200\n\n# Error count\nworkflow_error_count{workflow=\"blog_generator\", node=\"claude_call\", error_type=\"429\"} 1\n",[1367],{"type":32,"tag":89,"props":1368,"children":1369},{"__ignoreMap":16},[1370],{"type":37,"value":1365},{"type":32,"tag":33,"props":1372,"children":1373},{},[1374],{"type":37,"value":1375},"Visualizing these in Grafana dashboards shows which workflow consumes how many tokens, which nodes are bottlenecks, how often you hit rate limits. At Roibase, this dashboard revealed that Claude API latency dropped from 3 seconds to 1.8 seconds (via prompt caching + model upgrade).",{"type":32,"tag":33,"props":1377,"children":1378},{},[1379,1381,1387],{"type":37,"value":1380},"Alternative: send structured logs via webhook to a log aggregation service (Loki, Elasticsearch). After each execution, emit JSON like ",{"type":32,"tag":89,"props":1382,"children":1384},{"className":1383},[],[1385],{"type":37,"value":1386},"{\"workflow\": \"...\", \"execution_id\": \"...\", \"duration_ms\": ..., \"tokens\": {...}}",{"type":37,"value":1388},". Query this in ELK to analyze patterns over time.",{"type":32,"tag":40,"props":1390,"children":1392},{"id":1391},"what-to-do-now",[1393],{"type":37,"value":1394},"What to Do Now",{"type":32,"tag":33,"props":1396,"children":1397},{},[1398],{"type":37,"value":1399},"Building autonomous workflows with n8n + Claude API rests on three principles: idempotency (never process twice), error handling (retry + fallback), cost control (token budgets + caching). Without these three in production, your system becomes fragile — manual intervention grows necessary, automation's advantage disappears. When designing your workflow, ask these questions for every node: \"What happens if this fails?\", \"What if it receives the same input twice?\", \"What if it takes >10 seconds?\" Your answers drive the architecture.",{"type":32,"tag":33,"props":1401,"children":1402},{},[1403,1405,1412],{"type":37,"value":1404},"If you want to scale marketing operations with LLM, don't begin without these engineering principles. A system built on ",{"type":32,"tag":62,"props":1406,"children":1409},{"href":1407,"rel":1408},"https:\u002F\u002Fwww.roibase.com.tr\u002Fen\u002Ffirstparty",[66],[1410],{"type":37,"value":1411},"first-party data architecture",{"type":37,"value":1413}," can feed Claude's output into your decision engine — but the data itself must be clean and idempotent. Otherwise, automation becomes a garbage-in, garbage-out cycle.",{"type":32,"tag":1415,"props":1416,"children":1417},"style",{},[1418],{"type":37,"value":1419},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":16,"searchDepth":233,"depth":233,"links":1421},[1422,1423,1426,1427,1428,1429],{"id":42,"depth":205,"text":45},{"id":74,"depth":205,"text":77,"children":1424},[1425],{"id":126,"depth":233,"text":129},{"id":146,"depth":205,"text":149},{"id":1035,"depth":205,"text":1038},{"id":1349,"depth":205,"text":1352},{"id":1391,"depth":205,"text":1394},"markdown","content:en:ai:n8n-claude-api-autonomous-workflows.md","content","en\u002Fai\u002Fn8n-claude-api-autonomous-workflows.md","en\u002Fai\u002Fn8n-claude-api-autonomous-workflows","md",1785967487529]