kieai-ahmed

n8n community node for Kie.ai API - Image, Video, and Music generation

Package Information

Released: 4 mo ago
Downloads: 11 weekly / 80 monthly
Latest Version: 1.0.10

Documentation

n8n-nodes-kieai

Kie.ai n8n Community Node

This is a community node for n8n that allows you to interact with the Kie.ai API for image, video, and music generation.

Features

  • Image Generation: Text-to-image, Image-to-image, Upscale image with models like Midjourney, Flux, Nano Banana.
  • Video Generation: Text-to-video, Image-to-video with models like Kling, Runway, Veo.
  • Music Generation: Generate music from prompt with models like Suno.
  • Task Status: Get task status and polling helper for asynchronous operations.
  • Fetch Result: Fetch generated file URLs and download results as binary data.

Installation

To install this community node, you can use the n8n in-app installation or manually install it.

In-App Installation

  1. Go to Settings > Community Nodes in your n8n instance.
  2. Click on Install a custom community node.
  3. Enter n8n-nodes-kieai as the package name.
  4. Click Install.

Manual Installation

  1. Navigate to your n8n custom nodes folder (e.g., ~/.n8n/custom).
  2. Clone this repository:
    git clone https://github.com/manus/n8n-nodes-kieai.git
    cd n8n-nodes-kieai
    
  3. Install dependencies and build the project:
    npm install
    npm run build
    
  4. Restart your n8n instance.

npm Publish

To publish this package to npm, ensure you are logged in to npm and have the necessary permissions.

npm publish

Local Development

  1. Clone the repository:
    git clone https://github.com/manus/n8n-nodes-kieai.git
    cd n8n-nodes-kieai
    
  2. Install dependencies:
    npm install
    
  3. Start development mode (watches for changes and recompiles):
    npm run dev
    
  4. Link the node to your n8n instance (if running locally):
    npm link
    # In your n8n directory
    npm link n8n-nodes-kieai
    

Testing

To run linting checks:

npm run lint

To fix linting issues automatically:

npm run lintfix

Screenshots (Placeholders)

  • Kie.ai Credentials Setup
    Kie.ai Credentials Setup Placeholder

  • Image Generation Node
    Image Generation Node Placeholder

  • Video Generation Node
    Video Generation Node Placeholder

  • Music Generation Node
    Music Generation Node Placeholder

  • Task Status Node
    Task Status Node Placeholder

Credentials Setup

To use the Kie.ai node, you need to provide your API Key.

  1. In n8n, click on Credentials in the left sidebar.
  2. Click New Credential.
  3. Search for Kie.ai API.
  4. Enter your API Key (Bearer Token) obtained from Kie.ai API Key Management Page.
  5. Click Save.

Example Workflows

Example workflows are provided in the examples/ directory:

  • image-generation.json: Demonstrates text-to-image generation.
  • video-generation.json: Demonstrates text-to-video generation.
  • music-generation.json: Demonstrates music generation from a prompt.
  • polling-workflow.json: Demonstrates creating a task, polling its status, and downloading the result.

To import an example workflow:

  1. In n8n, go to Workflows.
  2. Click New > Import from JSON.
  3. Upload the desired .json file from the examples/ directory.

Polling Explanation

Kie.ai API operations are asynchronous. When you initiate a generation task (image, video, music), the API returns a taskId. You then need to poll the task status using the Task resource and Get Task Status operation. The node supports automatic polling with configurable Max Retries and Retry Interval.

  • Pending/Processing: The task is still being processed.
  • Success: The task completed successfully, and results are available.
  • Fail/Cancelled: The task failed or was cancelled.

Supported Models

Image Generation

  • Midjourney
  • Flux
  • Nano Banana
  • Grok Imagine

Video Generation

  • Kling
  • Runway
  • Veo

Music Generation

  • Suno

Troubleshooting

  • 401 Unauthorized: Ensure your API Key is correctly entered in the credentials.
  • Task Failed: Check the failMsg in the task status for details. This often indicates an issue with the input parameters.
  • Timeout: Increase Max Retries or Retry Interval in the Task Status node if your tasks take longer to complete.

Development Scripts

  • npm install: Install project dependencies.
  • npm run build: Compile TypeScript to JavaScript and copy assets.
  • npm run dev: Watch for changes and recompile during development.
  • npm run lint: Run ESLint to check for code style and errors.
  • npm run lintfix: Run ESLint and automatically fix issues.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Example API Payloads from Kie.ai Docs

Get Task Details (Response Example)

{
    "code": 505,
    "msg": "success",
    "data": {
        "taskId": "task_12345678",
        "model": "grok-imagine/text-to-image",
        "state": "success",
        "param": "{\"model\":\"grok-imagine/text-to-image\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"input\":{\"prompt\":\"Cinematic portrait...\",\"aspect_ratio\":\"3:2\"}}",
        "resultJson": "{\"resultUrls\":[\"https://example.com/generated-content.jpg\"]}",
        "failCode": "",
        "failMsg": "",
        "costTime": 15000,
        "completeTime": 1698765432000,
        "createTime": 1698765400000,
        "updateTime": 1698765432000,
        "progress": 45,
        "creditsConsumed": 50
    }
}

Generate Music (Request Example)

{
  "customMode": true,
  "instrumental": true,
  "model": "V4",
  "callBackUrl": "https://api.example.com/callback",
  "style": "Classical",
  "title": "Peaceful Piano Meditation",
  "negativeTags": "Heavy Metal, Upbeat Drums",
  "vocalGender": "m",
  "styleWeight": 0.65,
  "weirdnessConstraint": 0.65,
  "audioWeight": 0.65,
  "personaId": "persona_123",
  "personaModel": "style_persona"
}

Discussion