AutomationFlowsAI & RAG › Monetize Your Private LLM Models with X402 & Ollama

Monetize Your Private LLM Models with X402 & Ollama

By1Shot API @oneshotapi on n8n.io

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Webhook trigger★★★★☆ complexityAI-powered18 nodesN8N Nodes 1ShotChain LlmLm Ollama
AI & RAG Trigger: Webhook Nodes: 18 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #6597 — we link there as the canonical source.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "WRRtIr0VKNu7ZXuk",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "x402 + Ollama",
  "tags": [],
  "nodes": [
    {
      "id": "e2f6ea01-eab4-4b6c-810b-db3392dbd1aa",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -340,
        20
      ],
      "parameters": {
        "path": "92c5ca23-99a7-437d-85da-84aef8bd2a25",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "7af658fb-b731-47f1-8889-2f16af976155",
      "name": "Check for presence of X-HEADER",
      "type": "n8n-nodes-base.if",
      "position": [
        -120,
        20
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "2ff83590-61f3-41d8-8500-a96103c3844c",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.headers['x-payment'] }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "a28240bc-ee9b-4f1b-8b74-8e380232fa0a",
      "name": "Decode & Validate X-Payment",
      "type": "n8n-nodes-base.code",
      "position": [
        100,
        -60
      ],
      "parameters": {
        "jsCode": "try {\n    // Decode the x-payment header from base64\n    const xPaymentHeader = $input.first().json.headers['x-payment'];\n    const decodedXPayment = Buffer.from(xPaymentHeader, 'base64').toString('utf-8');\n\n    // Parse the decoded value into a JSON object\n    const decodedXPaymentJson = JSON.parse(decodedXPayment);\n\n    // Add the parsed JSON object to the input\n    $input.first().json.decodedXPayment = decodedXPaymentJson;\n\n    return $input.all();\n} catch (error) {\n    // Return an error object if the token format is invalid\n    return { error: \"invalid token format\" };\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "0f1efa84-3779-4f6c-87a3-844e25bba57a",
      "name": "Simulate Payment",
      "type": "n8n-nodes-1shot.oneShot",
      "position": [
        540,
        -100
      ],
      "parameters": {
        "params": "={\n  \"from\": \"{{ $json.decodedXPayment.from }}\",\n  \"to\": \"{{ $json.decodedXPayment.to }}\",\n  \"value\": \"{{ $json.decodedXPayment.value }}\",\n  \"validAfter\": \"{{ $json.decodedXPayment.validAfter }}\",\n  \"validBefore\": \"{{ $json.decodedXPayment.validBefore }}\",\n  \"nonce\": \"{{ $json.decodedXPayment.nonce }}\",\n  \"signature\": \"{{ $json.decodedXPayment.signature }}\"\n} ",
        "operation": "simulate",
        "contractMethodId": "b63aaaa1-059d-4c38-928a-33ad17d66827"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "437d945e-5d8b-4dc2-9e66-3675802ebc66",
      "name": "On Successful Payment Simulation",
      "type": "n8n-nodes-base.if",
      "position": [
        760,
        -100
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "81c67679-e256-4fd2-bed7-8f4272c2392b",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.success.toString() }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "2a555b8d-be2a-4df7-9178-a30a78afef11",
      "name": "1Shot API Submit & Wait",
      "type": "n8n-nodes-1shot.oneShotSynch",
      "position": [
        980,
        -180
      ],
      "parameters": {
        "params": "={\n\"from\": \"{{ $('Decode & Validate X-Payment').item.json.decodedXPayment.from }}\",\n\"to\": \"{{ $('Decode & Validate X-Payment').item.json.decodedXPayment.to }}\",\n\"value\": \"{{ $('Decode & Validate X-Payment').item.json.decodedXPayment.value }}\",\n\"validAfter\": \"{{ $('Decode & Validate X-Payment').item.json.decodedXPayment.validAfter }}\",\n\"validBefore\": \"{{ $('Decode & Validate X-Payment').item.json.decodedXPayment.validBefore }}\",\n\"nonce\": \"{{ $('Decode & Validate X-Payment').item.json.decodedXPayment.nonce }}\",\n\"signature\": \"{{ $('Decode & Validate X-Payment').item.json.decodedXPayment.signature }}\"\n}",
        "additionalFields": {},
        "contractMethodId": "b63aaaa1-059d-4c38-928a-33ad17d66827"
      },
      "credentials": {
        "oneShotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0311b436-3d0d-4958-a298-c3da32b3eb8e",
      "name": "Ensure Well Formatted Payment Payload",
      "type": "n8n-nodes-base.if",
      "position": [
        320,
        -60
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "6666e1f6-5e99-49d4-9f9a-a5a35cde4f74",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.decodedXPayment.signature }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "49394dfa-5ba3-4394-bde4-8c98efcd3927",
      "name": "Response: Missing or Invalid Payment Headers",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        540,
        120
      ],
      "parameters": {
        "options": {
          "responseCode": 402
        },
        "respondWith": "json",
        "responseBody": "{\n  \"x402Version\": \"1\",\n  \"error\": \"X-PAYMENT header has incorrect format\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "358ced9b-8e97-4347-8a0d-f18745e9c8a5",
      "name": "Response: Payment Invalid",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1200,
        0
      ],
      "parameters": {
        "options": {
          "responseCode": 402
        },
        "respondWith": "json",
        "responseBody": "{\n  \"x402Version\": \"1\",\n  \"error\": \"X-PAYMENT header did not verify\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "e859f032-9493-4aae-aa3f-06dbf6a60a27",
      "name": "Response: 200 - Payment Successful",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1700,
        -200
      ],
      "parameters": {
        "options": {
          "responseCode": 200
        },
        "respondWith": "text",
        "responseBody": "={ \"response\": \"{{ $json.text }}\" }"
      },
      "typeVersion": 1.3
    },
    {
      "id": "255c6a09-42bf-40d8-8622-d9f8a1916b07",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -440,
        -260
      ],
      "parameters": {
        "width": 360,
        "height": 220,
        "content": "## x402 Payment Endpoint \n\nThis workflow lets you monetize inference on private models hosted with Ollama in n8n. The x402 payment scheme lets user agents pass payments in the x-payment header field. \n\nLearn more about the [x402 payment](https://www.x402.org/) protocol. \n\nWatch the [YouTube tutorial](https://youtu.be/m3ThthLtj3g) video."
      },
      "typeVersion": 1
    },
    {
      "id": "ea3a1463-dd21-462b-9900-d103eba38849",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        580,
        -340
      ],
      "parameters": {
        "width": 360,
        "content": "## Any ERC-20 on any EVM\n\nWith the 1Shot API node, you can accept any ERC-20 with the appropriate `transferWithAuthorization` methods."
      },
      "typeVersion": 1
    },
    {
      "id": "af875673-eab4-46c8-8e0f-d550be13a45a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1240,
        -440
      ],
      "parameters": {
        "width": 320,
        "height": 200,
        "content": "## x402 + Ollama Inference\n\nSet up the LLM block to point at your Ollama inference engine. This will let you charge for agents to request queries to your private models. "
      },
      "typeVersion": 1
    },
    {
      "id": "2335ca81-fa1b-4a52-9d2a-030ac7ead35f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -820,
        220
      ],
      "parameters": {
        "width": 840,
        "height": 380,
        "content": "## Example Curl Command\n\nYou can test the webhook endpoint with a command like this (be sure to use a properly formatted x-payment header payload): \n\n```sh\n# swap out the URL here for you webhook URL endpoint\ncurl -X POST \\\n  https://n8n.1shotapi.dev/webhook-test/92c5ca23-99a7-437d-85da-84aef8bd2a25 \\\n  -H \"x-payment: YOUR-BASE64-ENCODED-PAYMENT-PAYLOAD\" \\\n  -H \"User-Agent: CustomUserAgent/1.0\" \\\n  -H \"Accept: application/json\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"query\": \"What is the capital of France?\"\n  }'\n```"
      },
      "typeVersion": 1
    },
    {
      "id": "f2fff145-fb18-4b3f-a166-f8dc4a61bf69",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        140,
        -360
      ],
      "parameters": {
        "width": 360,
        "height": 260,
        "content": "## Ensure Required Payment Details\n\nUse this block to add/check for payment detail requirements like minimum payment amount. \n\nYou might also want to add a condition in the block to ensure payments are sent to the correct address."
      },
      "typeVersion": 1
    },
    {
      "id": "07acfe27-d146-4e9a-8dc8-76e581bce92d",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1500,
        160
      ],
      "parameters": {
        "width": 700,
        "height": 840,
        "content": "## Ollama + ngrok Docker stack\n\nThis example assumes your n8n session is hosted separately from your Ollama instance. You can use ngrok to create a secure tunnel between your n8n workflow and your Ollama instance\n\n1. Create a free account at ngrok.com.\n2. Generate a free static URL under the Domains tab.\n3. Grab your ngrok auth token \n4. Spin up an Ollama + ngrok stack so that n8n can reach your private Ollama model: \n\nsudo NGROK_AUTHTOKEN=... TUNNEL_BASE_URL=https://your-static-url.ngrok-free.app docker compose up -d\n\nHere is your docker-compose.yaml: \n\n```sh\nservices:\n  ngrok:\n    image: ngrok/ngrok:latest\n    container_name: ngrok\n    command:\n      - \"http\"\n      - \"http://ollama:11434\"\n      - \"--url=${TUNNEL_BASE_URL}\"\n    environment:\n      NGROK_AUTHTOKEN: ${NGROK_AUTHTOKEN}\n      TUNNEL_BASE_URL: ${TUNNEL_BASE_URL}\n    ports:\n      - 4040:4040\n\n  ollama-service:\n    image: ollama/ollama:latest\n    container_name: ollama\n    volumes:\n      - ./ollama-volume:/root/.ollama\n    ports:\n      - \"1337:11434\"\n    deploy:\n      resources:\n        reservations:\n          devices:\n            - driver: nvidia\n              count: 1\n              capabilities: [gpu]\n```"
      },
      "typeVersion": 1
    },
    {
      "id": "6d080c36-2af1-434e-99ba-d4415051b020",
      "name": "Private Model Inference",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1280,
        -200
      ],
      "parameters": {
        "text": "={{ $('Webhook').item.json.body.query }}",
        "batching": {},
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "700dcb57-88df-4b50-84bb-5947353407e5",
      "name": "Ollama Engine",
      "type": "@n8n/n8n-nodes-langchain.lmOllama",
      "notes": "This example assumes your n8n session is hosted separately from your Ollama instance. You can use ngrok to create a secure tunnel between your n8n workflow and your Ollama instance\n\n1. Create a free account at ngrok.com.\n2. Generate a free static URL under the Domains tab.\n3. Grab your ngrok auth token \n4. Spin up an Ollama + ngrok stack so that n8n can reach your private Ollama model: \n\nsudo NGROK_AUTHTOKEN=... TUNNEL_BASE_URL=https://your-static-url.ngrok-free.app docker compose up -d\n\nHere is your docker-compose.yaml: \n\nservices:\n  ngrok:\n    image: ngrok/ngrok:latest\n    container_name: ngrok\n    command:\n      - \"http\"\n      - \"http://ollama:11434\"\n      - \"--url=${TUNNEL_BASE_URL}\"\n    environment:\n      NGROK_AUTHTOKEN: ${NGROK_AUTHTOKEN}\n      TUNNEL_BASE_URL: ${TUNNEL_BASE_URL}\n    ports:\n      - 4040:4040\n\n  ollama-service:\n    image: ollama/ollama:latest\n    container_name: ollama\n    volumes:\n      - ./ollama-volume:/root/.ollama\n    ports:\n      - \"1337:11434\"\n    deploy:\n      resources:\n        reservations:\n          devices:\n            - driver: nvidia\n              count: 1\n              capabilities: [gpu]",
      "position": [
        1540,
        20
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "ollamaApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "66d65719-7558-404e-8e94-b4fbf9f322dc",
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Check for presence of X-HEADER",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ollama Engine": {
      "ai_languageModel": [
        [
          {
            "node": "Private Model Inference",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simulate Payment": {
      "main": [
        [
          {
            "node": "On Successful Payment Simulation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1Shot API Submit & Wait": {
      "main": [
        [
          {
            "node": "Private Model Inference",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Response: Payment Invalid",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Private Model Inference": {
      "main": [
        [
          {
            "node": "Response: 200 - Payment Successful",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decode & Validate X-Payment": {
      "main": [
        [
          {
            "node": "Ensure Well Formatted Payment Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for presence of X-HEADER": {
      "main": [
        [
          {
            "node": "Decode & Validate X-Payment",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Response: Missing or Invalid Payment Headers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On Successful Payment Simulation": {
      "main": [
        [
          {
            "node": "1Shot API Submit & Wait",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Response: Payment Invalid",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ensure Well Formatted Payment Payload": {
      "main": [
        [
          {
            "node": "Simulate Payment",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Response: Missing or Invalid Payment Headers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Source: https://n8n.io/workflows/6597/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This visual workflow represents an AI-powered automated CV filtering system created using tools like n8n, Google Drive, Google Sheets, and Ollama (LLM) ### 📂 Google Drive Integration – Automatically s

Lm Ollama, Output Parser Autofixing, Output Parser Structured +3
AI & RAG

ANIS_HUB 1. Uses gmail, googleDrive, googleSheets, httpRequest. Webhook trigger; 89 nodes.

Gmail, Google Drive, Google Sheets +3
AI & RAG

This n8n workflow orchestrates a powerful suite of AI Agents and automations to manage and optimize various aspects of an e-commerce operation, particularly for platforms like Shopify. It leverages La

Google Sheets, HTTP Request, Slack +10
AI & RAG

secretaria. Uses postgres, n8n-nodes-evolution-api, openAi, httpRequest. Webhook trigger; 71 nodes.

Postgres, N8N Nodes Evolution Api, OpenAI +12
AI & RAG

The "Short Content" automation is a powerful, all-in-one solution designed to streamline the creation of short videos for social media, marketing, or personal projects. Leveraging cutting-edge AI tool

Chain Llm, Output Parser Structured, OpenAI Chat +4