{"product_id":"n8n-llm-retry-workflow-openai-anthropic-cost-logging","title":"n8n LLM Retry Workflow: OpenAI + Anthropic Cost Logging","description":"\u003ch3\u003eAutomatic LLM retries with OpenAI → Anthropic fallback, cost logging, and Telegram alerts\u003c\/h3\u003e\n\u003cp\u003eThis n8n workflow automatically retries OpenAI calls, falls back to Anthropic when needed, logs token\/cost estimates to an n8n Data Table, and notifies you via Telegram if every provider fails.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eTriggers from n8n Chat or another workflow\u003c\/strong\u003e by accepting a user prompt and an optional system prompt.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eSends the request to the active LLM provider\u003c\/strong\u003e (OpenAI primary), building provider-specific request parameters including model and max token settings.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eExtracts the response and usage\u003c\/strong\u003e from the HTTP result, capturing the answer, token usage, and any error details.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eRetries failures safely\u003c\/strong\u003e for rate limits, server errors, and timeouts using \u003cstrong\u003eexponential backoff\u003c\/strong\u003e (including honoring a \u003cem\u003eRetry-After\u003c\/em\u003e header when present).\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eFalls back to Anthropic\u003c\/strong\u003e after retries are exhausted or when encountering non-retryable errors.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eReturns a complete result payload\u003c\/strong\u003e including success status, provider\/model used, number of attempts, latency, token totals, estimated cost, and an attempt history log.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eLogs every run\u003c\/strong\u003e by ensuring the \u003cstrong\u003ellm_call_log\u003c\/strong\u003e n8n Data Table exists and writing \u003cstrong\u003eone log row per execution\u003c\/strong\u003e with token and cost estimates.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eAlerts on total failure\u003c\/strong\u003e by sending a \u003cstrong\u003eTelegram\u003c\/strong\u003e message if both OpenAI and Anthropic fail before returning the final result to the caller.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eHarden an n8n chatbot so transient OpenAI errors don’t break conversations.\u003c\/li\u003e\n  \u003cli\u003eRun cost-aware LLM automation for SaaS operations where token visibility matters.\u003c\/li\u003e\n  \u003cli\u003eProvide reliability for production workflows by switching to Anthropic automatically.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eProviders:\u003c\/strong\u003e OpenAI (primary) and Anthropic (fallback) via their API credentials.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCore logic nodes:\u003c\/strong\u003e \u003cem\u003eif\u003c\/em\u003e, \u003cem\u003eset\u003c\/em\u003e, \u003cem\u003ecode\u003c\/em\u003e, \u003cem\u003ewait\u003c\/em\u003e, \u003cem\u003eswitch\u003c\/em\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eNotifications:\u003c\/strong\u003e Telegram alert on total provider failure.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eLogging:\u003c\/strong\u003e writes per-run entries to the \u003cstrong\u003ellm_call_log\u003c\/strong\u003e n8n Data Table.\u003c\/li\u003e\n\u003c\/ul\u003e\n\u003cp\u003e\u003cstrong\u003eSetup note:\u003c\/strong\u003e Add OpenAI and Anthropic credentials to enable primary and fallback calls. If you don’t need storage, you can change\/remove the Data Table logging steps.\u003c\/p\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":46132841119923,"sku":"N8N-20168","price":36.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/nFxzY7H_VrWDbfQoXomkZ_ViQmdDrA.png?v=1790759606","url":"https:\/\/buyflowscripts.com\/products\/n8n-llm-retry-workflow-openai-anthropic-cost-logging","provider":"N8N Commerce","version":"1.0","type":"link"}