How to Generate Images using the sunra API

To create images with the sunra API, send a request to the specified endpoint including your input parameters. The API leverages pre-trained models to generate images based on text prompts, enabling you to produce visuals by describing them in natural language.

Here’s an example of generating an image from text using the sunra API:

import { sunra } from "@sunra/client";

const result = await sunra.subscribe("black-forest-labs/flux-kontext-max/text-to-image", {
  input: {
    prompt: 'A glass teapot with blooming flower tea inside, placed on a wooden table by a sunlit window with gentle morning light.',
    prompt_enhancer: true,
    aspect_ratio: '16:9',
    output_format: 'jpeg',
    safety_tolerance: 2
  },
  logs: true,
  onQueueUpdate: (update) => {
    console.log(update)
  },
});
console.log(result.data);
console.log(result.requestId);

How to Select the Model

sunra provides various image generation models. Choose one that suits your needs based on desired style and quality.

Available models include:

  • black-forest-labs/flux-kontext-pro: A unified model delivering local editing, generative modifications, and text-to-image generation in FLUX.1 quality. Processes text and image inputs for precise regional edits or full scene transformations at breakthrough speeds, pioneering iterative workflows that maintain character consistency across multiple editing turns.
  • black-forest-labs/flux-1.1-pro: The best of FLUX, offering state-of-the-art performance image generation at blazing speeds with top of the line prompt following, visual quality, image detail, and output diversity.
  • google-deepmind/imagen4: Imagen 4 generates photorealistic 2K images with fine detail, accurate text, and multilingual prompt support.

To select a model, specify its ID in the subscribe method as shown. Explore more models on the Text to Image Models page.