{
  "name": "DzRouter · 03 · Votre API d'IA (webhook)",
  "nodes": [
    {
      "id": "f1689c0c-1732-50a4-83f3-74a393d4f9b5",
      "name": "Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -520,
        -260
      ],
      "parameters": {
        "content": "## Votre API d'IA\n\n1. Installez le nœud communautaire **n8n-nodes-dzrouter** (Paramètres → Community nodes).\n2. Ouvrez chaque nœud DzRouter et choisissez votre identifiant **DzRouter API** (clé `sk-dz-…`).\n3. Cliquez **Test workflow** : un exemple algérien est déjà chargé.\n\nAppel (après activation) :\n```\ncurl -X POST https://VOTRE-N8N/webhook/dzrouter-ai \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"prompt\":\"Donne 3 idées de nom pour une pâtisserie à Oran\"}'\n```\n\n---\n\n<div dir=\"rtl\">\n\n### واجهة API خاصة بك\n\n1. ثبّت العقدة **n8n-nodes-dzrouter** (الإعدادات ← Community nodes).\n2. افتح كل عقدة DzRouter واختر بيانات اعتماد **DzRouter API** (مفتاح `sk-dz-…`).\n3. اضغط **Test workflow**: مثال جزائري جاهز للتجربة.\n\n</div>\n\n---\n\n### Your AI API\n\n1. Install the **n8n-nodes-dzrouter** community node (Settings → Community nodes).\n2. Open each DzRouter node and pick your **DzRouter API** credential (`sk-dz-…` key).\n3. Click **Test workflow**: an Algerian sample is already loaded.",
        "height": 640,
        "width": 440,
        "color": 4
      }
    },
    {
      "id": "67166310-8510-56fe-9985-c1150eb354cb",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        0
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "dzrouter-ai",
        "responseMode": "responseNode",
        "options": {}
      }
    },
    {
      "id": "1f1178e5-af28-51a2-8092-c100de77b0a6",
      "name": "Ask the model",
      "type": "n8n-nodes-dzrouter.dzRouter",
      "typeVersion": 1,
      "position": [
        260,
        0
      ],
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.body.model || 'openai/gpt-4o-mini' }}"
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "={{ $json.body.system || 'Tu es un assistant utile. Réponds dans la langue de la question.' }}"
            },
            {
              "role": "user",
              "content": "={{ $json.body.prompt }}"
            }
          ]
        },
        "simplify": true,
        "options": {
          "temperature": 0.7,
          "maxTokens": 800
        }
      }
    },
    {
      "id": "0045253a-befa-5d37-82f7-ae1630c78fec",
      "name": "Reply",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        520,
        0
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ answer: $json.text, model: $json.model, tokens: $json.usage, cost_pulses: $json.cost.pulses }) }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Ask the model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ask the model": {
      "main": [
        [
          {
            "node": "Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {
    "Webhook": [
      {
        "json": {
          "headers": {
            "content-type": "application/json"
          },
          "params": {},
          "query": {},
          "body": {
            "prompt": "Donne 3 idées de nom pour une pâtisserie traditionnelle à Oran, avec un slogan court.",
            "system": "Réponds en français, de façon concise."
          },
          "webhookUrl": "https://your-n8n/webhook/dzrouter-ai",
          "executionMode": "test"
        }
      }
    ]
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "templateId": "dzrouter"
  }
}
