npm package: @souptao/n8n-nodes-reilabs
Description: n8n node for ReiLabs Unit chat completions
Author: Your Name
Latest version: 1.0.2

# n8n-nodes-reilabs

This is an n8n community node that provides integration with ReiLabs Unit for chat completions. It allows you to use ReiLabs' OpenAI-compatible API within your n8n workflows, including with the AI Agent node.

## Features

- **OpenAI-Compatible**: Works with ReiLabs Unit's OpenAI-compatible chat completion API
- **AI Agent Integration**: Can be used as a chat model within n8n's AI Agent node
- **Secure Credentials**: API keys are stored securely using n8n's credential system
- **Function Calling**: Supports tools/function calling for advanced use cases
- **Configurable Parameters**: Full control over temperature, max tokens, penalties, and more

## Installation

### Community Node Installation (Recommended)

1. Go to **Settings > Community Nodes** in your n8n instance
2. Click **Install a community node**
3. Enter `n8n-nodes-reilabs`
4. Click **Install**

### Manual Installation

Navigate to your n8n installation directory and run:

```bash
npm install n8n-nodes-reilabs
```

For Docker installations, add this to your Dockerfile or docker-compose.yml:

```bash
npm install -g n8n-nodes-reilabs
```

### Local Development

1. Clone this repository
2. Install dependencies:
   ```bash
   npm install
   ```
3. Build the node:
   ```bash
   npm run build
   ```
4. Link to your n8n installation:
   ```bash
   npm link
   cd ~/.n8n/custom
   npm link n8n-nodes-reilabs
   ```

## Configuration

### Setting Up Credentials

1. In n8n, go to **Credentials** and click **Add Credential**
2. Search for **ReiLabs API**
3. Enter your ReiLabs Unit Secret Key
4. Click **Save**
5. Test the connection to verify it works

### Using the Node

1. Add the **ReiLabs Unit Chat Node** to your workflow
2. Select your ReiLabs API credentials
3. Configure the required parameters:
   - **Agent Model**: Currently supports `google/gemini-2.5-flash`
   - **Behaviour Prompt**: System-level instructions for the model
   - **Messages**: Array of message objects in OpenAI format

#### Example Messages Format

```json
[
  {
    "role": "user",
    "content": "Hello, can you help me?"
  }
]
```

#### Optional Parameters

- **Temperature** (0-2): Controls randomness (default: 0.7)
- **Max Tokens**: Maximum tokens to generate (default: 1024)
- **Top P** (0-1): Nucleus sampling parameter (default: 1)
- **Frequency Penalty** (-2 to 2): Reduces repetition (default: 0)
- **Presence Penalty** (-2 to 2): Encourages new topics (default: 0)
- **Tools**: JSON array of function definitions for function calling
- **Stop Sequences**: Comma-separated list of stop sequences

#### Function Calling Example

In the **Tools** field, provide a JSON array:

```json
[
  {
    "type": "function",
    "function": {
      "name": "get_weather",
      "description": "Get current temperature of given location",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "City and country (e.g. Paris, France)"
          }
        },
        "required": ["location"],
        "additionalProperties": false
      },
      "strict": true
    }
  }
]
```

## Using with AI Agent Node

This node is designed to work seamlessly with n8n's AI Agent node:

1. Add an **AI Agent** node to your workflow
2. In the AI Agent configuration, select **ReiLabs Unit Chat Node** as the chat model
3. Configure your agent's tools, memory, and other settings
4. The agent will use ReiLabs Unit for its language model capabilities

## API Reference

### Endpoint

- **Base URL**: `https://api.reilabs.org`
- **Chat Completions**: `/v1/chat/completions`

### Authentication

Uses Bearer token authentication:
```
Authorization: Bearer YOUR_REIGENT_UNIT_SECRET_KEY
```

### Request Format

```json
{
  "agentModel": "google/gemini-2.5-flash",
  "behaviourPrompt": "You are a helpful assistant",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "temperature": 0.7,
  "max_tokens": 1024,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0
}
```

### Response Format

```json
{
  "choices": [
    {
      "index": 0,
      "message": {
        "content": "Hello! How can I assist you today?",
        "role": "assistant"
      }
    }
  ]
}
```

## Troubleshooting

### Connection Issues

- Verify your API key is correct
- Check that you have access to the ReiLabs API
- Ensure your n8n instance can reach `https://api.reilabs.org`

### Invalid JSON Errors

- Ensure **Messages** and **Tools** fields contain valid JSON
- Use the JSON validator in your editor before pasting

### Model Not Available

- Currently only `google/gemini-2.5-flash` is supported
- Contact ReiLabs if you need access to additional models

## Development

### Project Structure

```
n8n-nodes-reilabs/
├── credentials/
│   └── ReiLabsApi.credentials.ts
├── nodes/
│   └── ReiLabsUnitChatNode/
│       ├── ReiLabsUnitChatNode.node.ts
│       └── reilabs.svg
├── package.json
├── tsconfig.json
└── README.md
```

### Building

```bash
npm run build
```

### Linting

```bash
npm run lint
npm run lintfix
```

### Formatting

```bash
npm run format
```

## Support

For issues related to:
- **This n8n node**: Open an issue on GitHub
- **ReiLabs API**: Contact ReiLabs support
- **n8n platform**: Visit [n8n community forum](https://community.n8n.io)

## License

MIT

## Resources

- [n8n Documentation](https://docs.n8n.io)
- [ReiLabs API Documentation](https://api.reilabs.org)
- [Creating n8n Nodes](https://docs.n8n.io/integrations/creating-nodes/)