Skip to main content

The generate method

The generate method creates a new image generation task.
const task = await mynth.generate(
  {
    prompt: "A beautiful landscape",
    model: "black-forest-labs/flux.1-dev",
    width: 1024,
    height: 1024,
  },
  { mode: "sync" } // Optional: "sync" (default) or "async"
);

Parameters

The first argument is the payload, which aligns with our API parameters.
ParamTypeDescription
promptstringThe text description of the image.
modelstringThe model ID to use.
widthnumberImage width.
heightnumberImage height.
negative_promptstring(Optional) What to avoid in the image.
seednumber(Optional) Random seed.

Sync vs Async

By default, generate waits for the task to complete (mode: "sync"). Pass { mode: "async" } to get the task ID immediately and poll for results later.
const task = await mynth.generate({ ... }, { mode: "async" });
console.log(task.id);

Content Moderation

The SDK fully supports content moderation with type inference for custom rating levels.

Standard Moderation

By default, moderation is disabled or uses standard levels if enabled.
const task = await mynth.generate({
  prompt: "...",
  content_rating: { enabled: true }
});

const images = task.getImages();
// images[0].content_rating?.level is typed as "sfw" | "nsfw"
if (images[0].content_rating?.level === "nsfw") {
  // Handle NSFW content
}

Custom Moderation Levels

When you define custom rating levels, the SDK infers the exact literal types for the result.
const task = await mynth.generate({
  prompt: "...",
  content_rating: {
    levels: [
      { value: "safe", description: "Safe for all audiences" },
      { value: "adult", description: "Adult content" }
    ]
  }
});

const images = task.getImages();
// images[0].content_rating?.level is typed as "safe" | "adult"
if (images[0].content_rating?.level === "adult") {
  // TypeScript knows this is a valid check
}