The MIDJ module provides a simple and efficient way to interact with the MIDJ API. Utilize the power of MIDJ with just a few lines of code in your Node.js application.
To use this module, you need to have a midj.app subscription.
-
Generate content with
generate
method. -
Fetch content using the trigger ID with
getByTrigger
method. -
Generate variation of content with
generateVariation
method. -
Upscale images with
upscaleImage
method.
To install the MIDJ module:
npm install @twozerotwo/midj
Start by importing and initializing the MIDJ class:
const MIDJ = require('@twozerotwo/midj');
const midj = new MIDJ({
authorization: 'YOUR_AUTHORIZATION_TOKEN'
});
Generate content based on a provided prompt:
midj.generate('Hello, world!').then(console.log);
Generate a variation of content:
midj.generateVariation(1, trigger_id_here, 'msg_hash_here').then(console.log);
Upscale an image:
midj.upscaleImage(1, trigger_id_here, 'msg_hash_here').then(console.log);
Generate content based on a provided prompt:
midj.Pregenerate('Hello, world!').then(console.log);
Generate a variation of content:
midj.PregenerateVariation(1, trigger_id_here, 'msg_hash_here').then(console.log);
Upscale an image:
midj.PreupscaleImage(1, trigger_id_here, 'msg_hash_here').then(console.log);
Fetch generated content by its trigger ID:
midj.getByTrigger(trigger_id_here).then(console.log);
The MIDJ
constructor accepts a configuration object:
const config = {
baseURL: 'https://api.midj.app', // Optional. This is the default.
authorization: 'YOUR_AUTHORIZATION_TOKEN' // Required.
};
const midj = new MIDJ(config);
⚠️ Always keep your authorization token secret. Do not expose it in client-side code.
All methods return an error object in case of any issues:
const response = await midj.generate('Hello, world!');
if (response.error) {
console.error('Error:', response.error);
} else {
console.log('Generated Content:', response);
}
For any bugs or feature requests, please open an issue on GitHub.