Skip to content
NEWMeet Alaaddin, your AI genie with a voice. trig8n launches 1 January 2027. See what is new

Library / Code, Git & Developer Tools

Code, Git & Developer Tools

Generate AI text and images with Claude and Stripe metered billing

When an API call/webhook arrives, it automates developer work with Claude using Stripe.

What it does

## AI SaaS Backend (Content Generation + Stripe Billing) A single n8n workflow that acts as the backend for an AI content-generation SaaS. A client app POSTs an API key + generation request to the webhook. n8n resolves the API key to a Stripe customer, checks the customer has an active subscription and hasn't exceeded their plan's usage limit, calls Claude to generate text or image content, records a Stripe usage record against the customer's metered subscription item, and returns the generated content (or a clear error) to the caller synchronously. ### How to set up 1. Import this workflow into n8n 2. Add credentials: Stripe API, Anthropic API (header auth, x-api-key) 3. Edit Set - Config: stripeUsagePriceId (the metered Price your subscription item uses), anthropicModel, planLimits (JSON map of Stripe price/plan id -> monthly generation limit), imageGenEndpoint (if using an external image API instead of Claude) 4. Point your app's API-key lookup at Stripe Customer metadata (this workflow expects customer.metadata.apiKey to match the incoming key) or swap in your own key store 5. Activate the workflow; the webhook URL is your API endpoint ### Requirements - Stripe API access (customers, subscriptions, subscription items, usage records) - Anthropic API access (Claude) for text generation; an image API for image generation ### How to customize - Swap the API-key -> customer lookup for a dedicated auth/DB service if you don't want to store keys in Stripe metadata - Replace the in-memory-per-run usage check with a real usage table (Postgres/Airtable) if you need cross-run accuracy beyond Stripe's own metered usage - Add a queue (instead of synchronous webhook response) for slow image generations - Extend planLimits per price id as you add new pricing tiers

The steps

  1. Webhook - Generation Request
  2. Set - Config
  3. HTTP Request - Stripe: Find Customer By API Key
  4. JS - Resolve Customer
  5. IF - Customer Found
  6. HTTP Request - Stripe: Get Active Subscription
  7. JS - Parse Subscription
  8. HTTP Request - Stripe: Get Current Period Usage
  9. JS - Check Entitlement
  10. IF - Entitlement OK
  11. Switch - Content Type
  12. HTTP Request - Claude: Generate Text Content
  13. JS - Parse Text Result
  14. HTTP Request - Generate Image Content

21 steps in total.

Similar automations