{
  "name": "Lab 1: LLM API Basics",
  "nodes": [
    {
      "parameters": {},
      "id": "trigger-001",
      "name": "Start Lab",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [100, 300],
      "notes": "Click 'Execute Workflow' to run this lab. The workflow will send a request to the OpenAI API and display the response."
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "system_prompt",
              "value": "STUDENT TASK: Replace this text with a system prompt that defines the AI's role and behavior. For example: 'You are a helpful cybersecurity analyst who explains concepts clearly and concisely.'"
            },
            {
              "name": "user_prompt",
              "value": "STUDENT TASK: Replace this text with your question or instruction. For example: 'Explain what a firewall does in simple terms.'"
            },
            {
              "name": "temperature",
              "value": "0.7"
            }
          ]
        },
        "options": {}
      },
      "id": "set-prompt-001",
      "name": "Configure Prompts",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [320, 300],
      "notes": "STUDENT TASK: Edit the three values in this node:\n\n1. system_prompt - Define the AI's role (e.g., 'You are a helpful assistant specializing in cybersecurity')\n2. user_prompt - Write your question or instruction\n3. temperature - Try values between 0.0 (deterministic) and 1.0 (creative)\n\nExperiment with different combinations and observe how they affect the output!"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": []
        },
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'gpt-4o-mini', messages: [ { role: 'system', content: $json.system_prompt }, { role: 'user', content: $json.user_prompt } ], temperature: parseFloat($json.temperature) }) }}",
        "options": {}
      },
      "id": "http-llm-001",
      "name": "Call OpenAI API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [540, 300],
      "notes": "This node sends your prompts to the OpenAI Chat Completions API.\n\nNOTE: You need to configure HTTP Header Auth credentials with:\n- Header Name: Authorization\n- Header Value: Bearer YOUR_API_KEY\n\nThe request structure follows the Chat API format with system and user roles."
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "model_used",
              "value": "={{ $json.model }}"
            },
            {
              "name": "response_text",
              "value": "={{ $json.choices[0].message.content }}"
            },
            {
              "name": "tokens_prompt",
              "value": "={{ $json.usage.prompt_tokens }}"
            },
            {
              "name": "tokens_completion",
              "value": "={{ $json.usage.completion_tokens }}"
            },
            {
              "name": "tokens_total",
              "value": "={{ $json.usage.total_tokens }}"
            }
          ]
        },
        "options": {}
      },
      "id": "set-output-001",
      "name": "Format Output",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [760, 300],
      "notes": "This node extracts the response text and token usage from the API response.\n\nAfter running, check the output to see:\n- The AI's response text\n- How many tokens were used for the prompt vs. completion\n- The total token count (this is what you'd be billed for)"
    }
  ],
  "connections": {
    "Start Lab": {
      "main": [
        [
          {
            "node": "Configure Prompts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure Prompts": {
      "main": [
        [
          {
            "node": "Call OpenAI API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call OpenAI API": {
      "main": [
        [
          {
            "node": "Format Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "instanceId": "lab-template"
  }
}
