How-to guide
How to Test Ad Injection Locally in n8n
This guide shows how to test ad injection locally in a n8n app, the goal being to run injection against a local/non-SSL server during development. It builds on the Monetzly server SDK, so the approach is specific to how n8n produces and streams responses.
Overview
You can develop ad injection for a n8n app locally before going to production. Point the SDK at a local ad-server address and turn SSL off; everything else — the injection call, session context, fallback — behaves the same as production.
This lets you verify that your n8n stream flows through injection and reaches the client correctly without needing production credentials wired up.
n8n apps are usually built for automated AI workflows, chatbot backends, and agent orchestration, so test ad injection locally typically comes up while a user is mid-conversation, the moment where monetization has to be additive rather than disruptive.
How this works on n8n
n8n runs on Node, so a Code node (or a small custom node) can import @monetzly/server-sdk and wrap the token output of an upstream LLM node. Because n8n items are usually discrete rather than a live token stream, confirm whether you inject over a buffered response or a true stream for your workflow.
Because Monetzly's inject() accepts any async token stream, the n8n side of this task is just mapping your output to it, no rewrite of your n8n model call.
Steps
- Set the server address to your local host (e.g. localhost:8080) and disable SSL.
- Run your n8n app and send a test prompt through the injection path.
- Confirm tokens stream to the client, then switch to your production host and SSL for release.
Integration snippet
// n8n Code node (runOnceForEachItem). TODO_VERIFY: streaming vs buffered output.
import { MonetzlySDK } from "@monetzly/server-sdk";
const sdk = new MonetzlySDK({
apiKey: $env.MONETZLY_API_KEY,
serverAddress: $env.MONETZLY_SERVER_ADDRESS,
});
await sdk.connect();
const llmText = $json.text; // output from the previous LLM node
async function* asChunks() { yield { content: llmText }; }
let out = "";
for await (const t of sdk.inject(asChunks(), { prompt: $json.prompt })) out += t.content ?? "";
await sdk.disconnect();
return { json: { text: out } };Frequently asked questions
Start monetizing in about 5 minutes
Wrap your existing LLM response stream with the Monetzly SDK and earn on every session, no paywall required.