Course/Chapter 8/1. Connecting to LLM Providers
    advanced
    Chapter 8: AI & LLM Integration

    1. Connecting to LLM Providers

    Set up credentials for AI services.

    15m Lesson 1 of 5

    n8n supports multiple AI providers through dedicated nodes and the HTTP Request node. Learn how to set up each one and choose the right model for your use case.

    Supported Providers

    • - OpenAI: GPT-4, GPT-3.5, DALL-E, Whisper
    • - Anthropic: Claude 3.5 Sonnet, Claude 3 Opus
    • - Google: Gemini Pro, Gemini Flash
    • - Ollama: Run local models (Llama 3, Mistral, etc.)

    Code Examples

    OpenAI Chat Completion via HTTP Request
    json
    {
      "method": "POST",
      "url": "https://api.openai.com/v1/chat/completions",
      "headers": {
        "Authorization": "Bearer {{ $env.OPENAI_API_KEY }}"
      },
      "body": {
        "model": "gpt-4",
        "messages": [
          { "role": "system", "content": "You are a helpful assistant." },
          { "role": "user", "content": "={{ $json.prompt }}" }
        ],
        "temperature": 0.7,
        "max_tokens": 500
      }
    }

    Pro Tips

    • 💡Use the dedicated OpenAI node for simplicity, but the HTTP Request node for full control over parameters

    Comprehension Quiz

    Answer 2 of 2 correctly to unlock lesson completion.

    1. Which parameter controls how creative/random AI responses are?

    2. What is the benefit of using the HTTP Request node over the OpenAI node?

    Pass the quiz above to unlock lesson completion