{
  "name": "Cernion OpenAI-compatible Chat Completions Example",
  "nodes": [
    {
      "parameters": {},
      "id": "manual-trigger",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "cernion-chat-completions-example",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        220
      ],
      "webhookId": "cernion-chat-completions-example"
    },
    {
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "api-host",
              "name": "cernionApiHost",
              "value": "https://api.cernion.de",
              "type": "string"
            },
            {
              "id": "token-placeholder",
              "name": "cernionToken",
              "value": "<CERNION_TOKEN>",
              "type": "string"
            },
            {
              "id": "question",
              "name": "question",
              "value": "={{ $json.body?.question || $json.question || $json.ticketText || 'Bitte fasse den Vorgang zusammen.' }}",
              "type": "string"
            },
            {
              "id": "ticket-id",
              "name": "ticketId",
              "value": "={{ $json.body?.ticketId || $json.ticketId || 'demo-ticket' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "set-context",
      "name": "Set Context",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        260,
        100
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $json.cernionApiHost + '/v1/chat/completions' }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{ 'Bearer ' + $json.cernionToken }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"cernion-default\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"Du bist Cernion und beantwortest fachlich, knapp und nachvollziehbar.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": $json.question\n    }\n  ],\n  \"temperature\": 0.2\n}",
        "options": {
          "timeout": 45000
        }
      },
      "id": "cernion-chat-completions",
      "name": "Cernion Chat Completions",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        560,
        100
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "ticket-note",
              "name": "ticketNote",
              "value": "={{ $json.choices?.[0]?.message?.content || $json.body?.choices?.[0]?.message?.content || 'Keine Antwort von Cernion erhalten.' }}",
              "type": "string"
            },
            {
              "id": "ticket-status",
              "name": "ticketStatus",
              "value": "draft-note-ready",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "set-ticket-note",
      "name": "Set Ticket Note",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        840,
        100
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"ticketId\": $json.ticketId || 'demo-ticket',\n  \"ticketNote\": $json.ticketNote,\n  \"status\": $json.ticketStatus\n}",
        "options": {}
      },
      "id": "respond-to-webhook",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1120,
        100
      ]
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Set Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Set Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Context": {
      "main": [
        [
          {
            "node": "Cernion Chat Completions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cernion Chat Completions": {
      "main": [
        [
          {
            "node": "Set Ticket Note",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Ticket Note": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false,
  "versionId": "cernion-public-example-placeholder-only"
}
