arrow_backGuides / Scripts Library
Updated: August 2026 · updated biweekly

Scripts Library

Ready-made scripts and automations — n8n workflows, Python code for calling models and RAG, and Shell commands. Copy, download and run them yourself. All free.

code scripts

How to use

1. Download / copy

Every script can be copied or downloaded as a ready file (‎.json / .py / .sh‎).

2. Add your keys

Replace YOUR_API_KEY and the bracketed [details] with your own.

3. Run

Import n8n workflows via Import from File; run Python/Shell directly.

Safety: never put an API key into code you've shared. Use environment variables (OPENAI_API_KEY) or a .env file. The model IDs in the examples are correct as of August 2026 and may be updated.

n8n Workflows

Webhook → AI → reply
n8nJSON
{
  "name": "Webhook to AI Reply",
  "nodes": [
    { "parameters": { "httpMethod": "POST", "path": "ai-reply" },
      "name": "Webhook", "type": "n8n-nodes-base.webhook",
      "typeVersion": 1, "position": [400, 300] },
    { "parameters": { "url": "https://api.openai.com/v1/chat/completions",
        "method": "POST", "sendHeaders": true,
        "headerParameters": { "parameters": [
          { "name": "Authorization", "value": "Bearer YOUR_API_KEY" },
          { "name": "Content-Type", "value": "application/json" } ] },
        "sendBody": true, "specifyBody": "json",
        "jsonBody": "={\"model\":\"gpt-5.6\",\"messages\":[{\"role\":\"user\",\"content\":$json.body.message}]}" },
      "name": "OpenAI", "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4, "position": [640, 300] },
    { "parameters": { "respondWith": "json",
        "responseBody": "={{ $json.choices[0].message.content }}" },
      "name": "Respond", "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1, "position": [880, 300] }
  ],
  "connections": {
    "Webhook": { "main": [[{ "node": "OpenAI", "type": "main", "index": 0 }]] },
    "OpenAI": { "main": [[{ "node": "Respond", "type": "main", "index": 0 }]] }
  }
}
Scheduled — daily digest to email
n8nJSON
{
  "name": "Daily Digest to Email",
  "nodes": [
    { "parameters": { "rule": { "interval": [{ "field": "cronExpression", "expression": "0 8 * * *" }] } },
      "name": "Every day 08:00", "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1, "position": [400, 300] },
    { "parameters": { "url": "[YOUR_DATA_SOURCE_URL]" },
      "name": "Fetch Data", "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4, "position": [640, 300] },
    { "parameters": { "url": "https://api.openai.com/v1/chat/completions",
        "method": "POST", "sendHeaders": true,
        "headerParameters": { "parameters": [
          { "name": "Authorization", "value": "Bearer YOUR_API_KEY" } ] },
        "sendBody": true, "specifyBody": "json",
        "jsonBody": "={\"model\":\"gpt-5.6\",\"messages\":[{\"role\":\"user\",\"content\":\"Summarize to 5 points: \"+ $json.data}]}" },
      "name": "Summarize", "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4, "position": [880, 300] },
    { "parameters": { "toEmail": "[YOUR_EMAIL]", "subject": "Daily Digest",
        "text": "={{ $json.choices[0].message.content }}" },
      "name": "Send Email", "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2, "position": [1120, 300] }
  ],
  "connections": {
    "Every day 08:00": { "main": [[{ "node": "Fetch Data", "type": "main", "index": 0 }]] },
    "Fetch Data": { "main": [[{ "node": "Summarize", "type": "main", "index": 0 }]] },
    "Summarize": { "main": [[{ "node": "Send Email", "type": "main", "index": 0 }]] }
  }
}

Python — AI

OpenAI — chat call
PythonOpenAI
# pip install openai   |   export OPENAI_API_KEY="sk-..."
from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY from env

resp = client.chat.completions.create(
    model="gpt-5.6",
    messages=[
        {"role": "system", "content": "Answer concisely."},
        {"role": "user", "content": "[your request here]"},
    ],
)
print(resp.choices[0].message.content)
Claude — message call
PythonAnthropic
# pip install anthropic   |   export ANTHROPIC_API_KEY="sk-ant-..."
import anthropic

client = anthropic.Anthropic()

msg = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "[your request here]"}],
)
print(msg.content[0].text)
Batch processing of files
PythonBatch
# Process every text file in a folder with a cheap model
import os, glob
from openai import OpenAI

client = OpenAI()

for path in glob.glob("input/*.txt"):
    text = open(path, encoding="utf-8").read()
    resp = client.chat.completions.create(
        model="gpt-5.6",  # for high volume consider a cheaper model
        messages=[{"role": "user", "content": f"Summarize in 3 points:\n{text}"}],
    )
    out = path.replace("input/", "output/")
    os.makedirs("output", exist_ok=True)
    open(out, "w", encoding="utf-8").write(resp.choices[0].message.content)
    print("done:", out)
RAG — query over documents
PythonRAG
# Minimal RAG: embed -> retrieve -> answer
from openai import OpenAI
import numpy as np

client = OpenAI()
docs = ["[document 1]", "[document 2]", "[document 3]"]

def embed(texts):
    r = client.embeddings.create(model="text-embedding-3-small", input=texts)
    return np.array([e.embedding for e in r.data])

doc_vecs = embed(docs)

def ask(question):
    q = embed([question])[0]
    sims = doc_vecs @ q
    top = docs[int(sims.argmax())]  # the most relevant passage
    r = client.chat.completions.create(
        model="gpt-5.6",
        messages=[{"role": "system", "content": f"Answer only from:\n{top}\nIf there is no answer, say 'I don't know'."},
                  {"role": "user", "content": question}],
    )
    return r.choices[0].message.content

print(ask("[your question]"))

Shell / CLI

Run a local model (Ollama)
Shelllocal · free
# Install Ollama from https://ollama.com , then:
ollama run qwen3            # interactive chat, runs locally for free

# or via the local API (port 11434):
curl http://localhost:11434/api/generate -d '{
  "model": "qwen3",
  "prompt": "Write a Python function that returns Fibonacci numbers",
  "stream": false
}'
Call OpenAI from the CLI (curl)
Shellcurl
export OPENAI_API_KEY="sk-..."

curl https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6",
    "messages": [{"role": "user", "content": "[your request]"}]
  }'
tips_and_updates

Want more?

The library is updated biweekly with new scripts. You'll find the prompts in the prompt library, and the full explanation in the n8n guide.