Loading...
Self-hosted workflow automation. Custom node, workflow templates, and Docker deployment.
// n8n-nodes-butterflyapi/nodes/ButterflyApi/ButterflyApi.node.ts
import {
IExecuteFunctions,
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
export class ButterflyApi implements INodeType {
description: INodeTypeDescription = {
displayName: 'ButterflyAPI',
name: 'butterflyApi',
icon: 'file:butterflyapi.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"]}}',
description: 'AI-powered image and video processing',
defaults: {
name: 'ButterflyAPI',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'butterflyApiCredentials',
required: true,
},
],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
options: [
{ name: 'Cartoon', value: 'cartoon', description: 'Transform image to cartoon style' },
{ name: 'Remove Background', value: 'background-remove', description: 'Remove image background' },
{ name: 'Upscale', value: 'upscale', description: 'Upscale image resolution' },
{ name: 'Enhance', value: 'image-enhance', description: 'Enhance image quality' },
{ name: 'Face Restore', value: 'face-restore', description: 'Restore blurry faces' },
{ name: 'Text to Image', value: 'text-to-image', description: 'Generate image from text' },
{ name: 'Video Generate', value: 'video-gen', description: 'Generate video from text' },
],
default: 'image-enhance',
},
{
displayName: 'Image URL',
name: 'imageUrl',
type: 'string',
default: '',
required: true,
displayOptions: {
hide: { operation: ['text-to-image', 'video-gen'] },
},
description: 'URL of the image to process',
},
{
displayName: 'Prompt',
name: 'prompt',
type: 'string',
default: '',
required: true,
displayOptions: {
show: { operation: ['text-to-image', 'video-gen'] },
},
description: 'Text prompt for generation',
},
{
displayName: 'Style',
name: 'style',
type: 'options',
displayOptions: { show: { operation: ['cartoon'] } },
options: [
{ name: 'Pixar 3D', value: 'pixar' },
{ name: 'Anime', value: 'anime' },
{ name: 'Disney', value: 'disney' },
{ name: 'Studio Ghibli', value: 'ghibli' },
{ name: 'Comic Book', value: 'comic' },
{ name: 'Simpsons', value: 'simpsons' },
{ name: 'Watercolor', value: 'watercolor' },
{ name: 'Oil Painting', value: 'oil-painting' },
],
default: 'pixar',
},
{
displayName: 'Scale Factor',
name: 'scale',
type: 'options',
displayOptions: { show: { operation: ['upscale'] } },
options: [
{ name: '2x', value: 2 },
{ name: '4x', value: 4 },
],
default: 2,
},
{
displayName: 'Duration',
name: 'duration',
type: 'options',
displayOptions: { show: { operation: ['video-gen'] } },
options: [
{ name: '5 seconds', value: '5s' },
{ name: '10 seconds', value: '10s' },
],
default: '5s',
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
const credentials = await this.getCredentials('butterflyApiCredentials');
for (let i = 0; i < items.length; i++) {
const operation = this.getNodeParameter('operation', i) as string;
const body: Record<string, any> = { api: operation };
if (['text-to-image', 'video-gen'].includes(operation)) {
body.prompt = this.getNodeParameter('prompt', i) as string;
if (operation === 'video-gen') {
body.duration = this.getNodeParameter('duration', i) as string;
}
} else {
body.imageUrl = this.getNodeParameter('imageUrl', i) as string;
if (operation === 'cartoon') {
body.style = this.getNodeParameter('style', i) as string;
}
if (operation === 'upscale') {
body.scale = this.getNodeParameter('scale', i) as number;
}
}
const response = await this.helpers.request({
method: 'POST',
url: 'https://butterflyapi.com/api/v1/run',
headers: {
'Authorization': `Bearer ${credentials.apiKey}`,
'Content-Type': 'application/json',
},
body,
json: true,
});
returnData.push({ json: response });
}
return [returnData];
}
}Settings → Credentials → New
Name: AuthorizationValue: Bearer YOUR_API_KEYMethod: POST
URL: https://butterflyapi.com/api/v1/runNeed help with n8n setup?