Skip to main content

apiV1DiffusionPost()

Create a new text-to-image generation task.
const { Configuration, ImageApi } = require('@legnext-api/js-sdk');

const config = new Configuration({
    basePath: 'https://api.legnext.ai'
});

const imageApi = new ImageApi(config);
const apiKey = 'your-api-key-here';

const body = {
    text: 'a serene mountain landscape at sunset',
    callback: 'https://your-domain.com/webhook' // Optional
};

imageApi.apiV1DiffusionPost(apiKey, body, (error, data, response) => {
    if (error) {
        console.error('Error:', error);
    } else {
        console.log('Job ID:', data.job_id);
    }
});
Promise-based:
imageApi.apiV1DiffusionPost(apiKey, body)
    .then(response => {
        console.log('Job ID:', response.data.job_id);
    })
    .catch(error => {
        console.error('Error:', error);
    });
Async/Await:
async function generateImage() {
    try {
        const response = await imageApi.apiV1DiffusionPost(apiKey, body);
        console.log('Job ID:', response.data.job_id);
    } catch (error) {
        console.error('Error:', error);
    }
}
Parameters:
  • xApiKey (String): Your API key
  • body (Object): Request body with:
    • text (String): Text prompt (1-8192 characters)
    • callback (String, optional): Webhook URL
Returns: Promise resolving to response with job_id and status

apiV1VaryPost()

Create variations of a generated image.
const body = {
    jobId: 'original-job-id',
    imageNo: 0,
    type: 1, // 0=Subtle, 1=Strong
    remixPrompt: 'add more clouds' // Optional
};

const response = await imageApi.apiV1VaryPost(apiKey, body);
console.log('Variation Job ID:', response.jobId);

apiV1UpscalePost()

Upscale a generated image.
const body = {
    jobId: 'original-job-id',
    imageNo: 0,
    type: 1 // 0=Subtle, 1=Creative
};

const response = await imageApi.apiV1UpscalePost(apiKey, body);
console.log('Upscale Job ID:', response.jobId);

apiV1RerollPost()

Regenerate with the same prompt.
const body = {
    jobId: 'original-job-id'
};

await imageApi.apiV1RerollPost(apiKey, body);

apiV1BlendPost()

Blend 2-5 images together.
const body = {
    imgUrls: [
        'https://example.com/image1.png',
        'https://example.com/image2.png'
    ],
    aspect_ratio: '1:1', // "2:3", "1:1", or "3:2"
    callback: 'https://your-domain.com/webhook'
};

await imageApi.apiV1BlendPost(apiKey, body);

apiV1DescribePost()

Generate text descriptions from an image.
const body = {
    imgUrl: 'https://example.com/image.png'
};

await imageApi.apiV1DescribePost(apiKey, body);

apiV1EditPost()

Edit an image by positioning it on a canvas and filling empty areas.
const body = {
    jobId: 'original-job-id',
    imageNo: 0,
    canvas: {
        width: 1024,
        height: 1024
    },
    imgPos: {
        width: 512,
        height: 512,
        x: 256,
        y: 256
    },
    remixPrompt: 'A beautiful landscape with mountains',
    callback: 'https://your-domain.com/webhook'
};

await imageApi.apiV1EditPost(apiKey, body);

apiV1InpaintPost()

Fill masked regions in an image.
const body = {
    jobId: 'original-job-id',
    imageNo: 0,
    mask: {
        areas: [
            {
                width: 500,
                height: 500,
                points: [10, 10, 10, 100, 100, 100, 100, 10] // XYXY coordinates (clockwise)
            }
        ]
    },
    remixPrompt: 'Add a tree in the center', // Optional
    callback: 'https://your-domain.com/webhook'
};

await imageApi.apiV1InpaintPost(apiKey, body);

apiV1OutpaintPost()

Extend image boundaries by scaling.
const body = {
    jobId: 'original-job-id',
    imageNo: 0,
    scale: 1.5, // Extension scale ratio (1.1 to 2.0)
    remixPrompt: 'clouds over the sky', // Optional
    callback: 'https://your-domain.com/webhook'
};

await imageApi.apiV1OutpaintPost(apiKey, body);

apiV1PanPost()

Create panoramic or panned views.
const body = {
    jobId: 'original-job-id',
    imageNo: 0,
    direction: 1, // 0=Down, 1=Right, 2=Up, 3=Left
    scale: 1.5, // Extension scale ratio (1.1 to 3.0)
    remixPrompt: 'a lake near the mountain', // Optional
    callback: 'https://your-domain.com/webhook'
};

await imageApi.apiV1PanPost(apiKey, body);

apiV1RemixPost()

Remix an image with a new prompt and style intensity.
const body = {
    jobId: 'original-job-id',
    imageNo: 0,
    remixPrompt: 'Change style to watercolor painting',
    mode: 0, // 0=Strong, 1=Subtle
    callback: 'https://your-domain.com/webhook'
};

await imageApi.apiV1RemixPost(apiKey, body);

apiV1ShortenPost()

Optimize and simplify prompts.
const body = {
    prompt: 'your very long and detailed prompt here...'
};

const response = await imageApi.apiV1ShortenPost(apiKey, body);
console.log('Optimized prompt:', response.shortenedPrompt);

Next Steps