openai-compatible-node

Package Information

Released: 6/30/2025
Downloads: 19 weekly / 142 monthly
Latest Version: 0.0.1
Author: sherman.zhou

Documentation

n8n OpenAI Compatible Node

This n8n node allows you to interact with any OpenAI-compatible API service like qwen etc. It supports both chat completions and text completions, making it compatible with various AI model providers that follow the OpenAI API specification.

Features

  • Chat Completions: Generate responses using the chat completion endpoint (/v1/chat/completions)
  • Text Completions: Generate text using the completion endpoint (/v1/completions)
  • Flexible Configuration: Configure base URL, model, and API key for any OpenAI-compatible service
  • Advanced Parameters: Support for temperature, max tokens, top-p, frequency penalty, presence penalty, and stop sequences
  • Error Handling: Robust error handling with continue-on-fail support

Supported Services

This node works with any service that implements the OpenAI API specification, including:

  • OpenAI API
  • Azure OpenAI
  • Anthropic Claude (via OpenAI-compatible wrapper)
  • Local models (Ollama, LM Studio, etc.)
  • Other OpenAI-compatible providers

Installation

Manual Installation

  1. Clone or download this repository
  2. Install dependencies:
    npm install
    
  3. Build the node:
    npm run build
    
  4. Copy the dist folder to your n8n custom nodes directory:
    cp -r dist ~/.n8n/custom/
    
  5. Restart n8n

Using npm

npm install n8n-nodes-openai-compatible-node

Usage

1. Configure Credentials

  1. In n8n, go to SettingsCredentials
  2. Click Add Credential
  3. Search for "OpenAI Compatible API"
  4. Configure:
    • Base URL: The base URL of your OpenAI-compatible service (e.g., https://api.openai.com, https://your-service.com)
    • API Key: Your API key for the service

2. Add the Node

  1. In your workflow, add the "OpenAI Compatible" node
  2. Select the credentials you created
  3. Choose the operation:
    • Chat Completion: For conversational AI responses
    • Text Completion: For text generation

3. Configure Parameters

Chat Completion

  • Model: The model name (e.g., gpt-3.5-turbo, gpt-4)
  • Messages: Array of messages with role (system, user, assistant) and content
  • Additional Fields: Optional parameters like temperature, max tokens, etc.

Text Completion

  • Model: The model name (e.g., text-davinci-003)
  • Prompt: The text prompt to complete
  • Additional Fields: Optional parameters like temperature, max tokens, etc.

4. Advanced Parameters

  • Temperature (0-2): Controls randomness. Lower values = more deterministic
  • Max Tokens: Maximum number of tokens to generate
  • Top P (0-1): Controls diversity via nucleus sampling
  • Frequency Penalty (-2 to 2): Penalizes new tokens based on frequency
  • Presence Penalty (-2 to 2): Penalizes new tokens based on presence
  • Stop: Sequences where generation stops

Examples

Chat Completion Example

{
  "operation": "chatCompletion",
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Hello, how are you?"
    }
  ],
  "temperature": 0.7,
  "max_tokens": 1000
}

Text Completion Example

{
  "operation": "textCompletion",
  "model": "text-davinci-003",
  "prompt": "Write a short story about a robot learning to paint.",
  "temperature": 0.8,
  "max_tokens": 500
}

Configuration Examples

OpenAI API

  • Base URL: https://api.openai.com
  • API Key: Your OpenAI API key

Azure OpenAI

  • Base URL: https://your-resource.openai.azure.com/openai/deployments/your-deployment
  • API Key: Your Azure OpenAI API key

Local Ollama

  • Base URL: http://localhost:11434/v1
  • API Key: (leave empty or use any value)

Anthropic Claude (via OpenAI wrapper)

  • Base URL: https://api.anthropic.com/v1
  • API Key: Your Anthropic API key

Development

Prerequisites

  • Node.js 16+
  • npm or yarn
  • n8n development environment

Setup

  1. Clone the repository
  2. Install dependencies: npm install
  3. Build: npm run build
  4. Link to n8n: npm link (in n8n directory)

Scripts

  • npm run build: Build the node
  • npm run dev: Watch mode for development
  • npm run lint: Run ESLint
  • npm run format: Format code with Prettier

Troubleshooting

Common Issues

  1. "Base URL and API Key are required"

    • Ensure both fields are filled in the credentials
  2. "At least one message is required for chat completion"

    • Add at least one message in the Messages section
  3. "Prompt is required for text completion"

    • Add a prompt in the Prompt field
  4. Authentication errors

    • Verify your API key is correct
    • Check if the base URL is accessible

Debug Mode

Enable debug logging in n8n to see detailed request/response information.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Support

For issues and questions:

  • Create an issue on GitHub
  • Check the n8n documentation
  • Join the n8n community

Discussion