> ## Documentation Index
> Fetch the complete documentation index at: https://docs.modelslab.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Text to Image

> Create high quality images from text using the FLUX model.

<img src="https://mintcdn.com/mod/i8dYICFkuz1vpdrI/images/image-generation/flux/assets/images/Text-to-image-1-a226305d52e197b14c4cc0b1534ea06c.jpg?fit=max&auto=format&n=i8dYICFkuz1vpdrI&q=85&s=bcb4615889963132d06bd5293e8e6684" alt="Text to image endpoint result" width="691" height="518" data-path="images/image-generation/flux/assets/images/Text-to-image-1-a226305d52e197b14c4cc0b1534ea06c.jpg" />

Generate photorealistic images from text descriptions using the FLUX model. FLUX excels at creating highly detailed, realistic images with excellent prompt adherence.

## Request

Make a `POST` request to the endpoint below with the required parameters.

```bash theme={null}
POST https://modelslab.com/api/v6/images/text2img
```

## Parameters

<ParamField body="key" type="string" required>
  Your API key for authentication. Get one from your [dashboard](https://modelslab.com/dashboard/api-keys).
</ParamField>

<ParamField body="model_id" type="string" required>
  The model to use for generation. Use `flux` for the FLUX model.
</ParamField>

<ParamField body="prompt" type="string" required>
  Text description of the image you want to generate. Be specific and detailed for best results.
</ParamField>

<ParamField body="negative_prompt" type="string">
  Things you don't want in the image. Example: "blurry, low quality, distorted"
</ParamField>

<ParamField body="width" type="integer" default="512">
  Image width in pixels. Must be between 256-1024 and divisible by 8.
</ParamField>

<ParamField body="height" type="integer" default="512">
  Image height in pixels. Must be between 256-1024 and divisible by 8.
</ParamField>

<ParamField body="samples" type="integer" default="1">
  Number of images to generate. Range: 1-4.
</ParamField>

<ParamField body="num_inference_steps" type="integer" default="30">
  Number of denoising steps. Higher values produce more detailed images but take longer. Range: 20-50.
</ParamField>

<ParamField body="guidance_scale" type="float" default="7.5">
  How closely to follow the prompt. Higher values = more literal interpretation. Range: 1-20.
</ParamField>

<ParamField body="safety_checker" type="string" default="yes">
  Enable NSFW content filter. Values: "yes" or "no".
</ParamField>

<ParamField body="seed" type="integer">
  Random seed for reproducible results. Use the same seed with same parameters to get identical images.
</ParamField>

<ParamField body="clip_skip" type="integer" default="2">
  Number of CLIP layers to skip. Affects style interpretation. Range: 1-4.
</ParamField>

<ParamField body="webhook" type="string">
  URL to receive a POST request when generation completes. See [Webhooks](/webhooks).
</ParamField>

<ParamField body="track_id" type="string">
  Your custom identifier to track this request. Returned in response and webhook.
</ParamField>

## Request Example

<CodeGroup>
  ```json Body theme={null}
  {
      "key": "your_api_key",
      "model_id": "flux",
      "prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner)), blue eyes, shaved side haircut, hyper detail, cinematic lighting, magic neon, dark red city, Canon EOS R3, nikon, f/1.4, ISO 200, 1/160s, 8K, RAW, unedited, symmetrical balance, in-frame, 8K",
      "negative_prompt": "blurry, low quality, distorted, deformed",
      "width": 512,
      "height": 512,
      "samples": 1,
      "num_inference_steps": 31,
      "safety_checker": "no",
      "seed": null,
      "guidance_scale": 7.5,
      "clip_skip": 2,
      "webhook": null,
      "track_id": null
  }
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://modelslab.com/api/v6/images/text2img",
      json={
          "key": "your_api_key",
          "model_id": "flux",
          "prompt": "ultra realistic portrait of a cyberpunk woman, blue eyes, cinematic lighting, 8K",
          "negative_prompt": "blurry, low quality, distorted",
          "width": 512,
          "height": 512,
          "samples": 1,
          "num_inference_steps": 31,
          "guidance_scale": 7.5
      }
  )

  data = response.json()
  print(data)
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://modelslab.com/api/v6/images/text2img", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      key: "your_api_key",
      model_id: "flux",
      prompt: "ultra realistic portrait of a cyberpunk woman, blue eyes, cinematic lighting, 8K",
      negative_prompt: "blurry, low quality, distorted",
      width: 512,
      height: 512,
      samples: 1,
      num_inference_steps: 31,
      guidance_scale: 7.5
    })
  });

  const data = await response.json();
  console.log(data);
  ```

  ```bash cURL theme={null}
  curl -X POST "https://modelslab.com/api/v6/images/text2img" \
    -H "Content-Type: application/json" \
    -d '{
      "key": "your_api_key",
      "model_id": "flux",
      "prompt": "ultra realistic portrait of a cyberpunk woman, blue eyes, cinematic lighting, 8K",
      "negative_prompt": "blurry, low quality, distorted",
      "width": 512,
      "height": 512,
      "samples": 1,
      "num_inference_steps": 31,
      "guidance_scale": 7.5
    }'
  ```
</CodeGroup>

## Response

### Success Response

When the image is generated successfully:

```json theme={null}
{
  "status": "success",
  "generationTime": 2.45,
  "id": 12345678,
  "output": [
    "https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/abc123.png"
  ],
  "proxy_links": {
    "0": "https://cdn.modelslab.com/generations/abc123.png"
  },
  "meta": {
    "prompt": "ultra realistic portrait...",
    "model_id": "flux",
    "width": 512,
    "height": 512,
    "seed": 12345
  }
}
```

### Processing Response

For complex requests, you may receive a processing status:

```json theme={null}
{
  "status": "processing",
  "id": 12345678,
  "eta": 10,
  "message": "Your request is being processed"
}
```

<Tip>
  When you receive a processing response, use the [Fetch endpoint](/image-generation/community-models/dreambooth-fetch-queue-image) to poll for results.
</Tip>

### Error Response

```json theme={null}
{
  "status": "error",
  "message": "prompt is required"
}
```

## Response Fields

| Field            | Type    | Description                            |
| ---------------- | ------- | -------------------------------------- |
| `status`         | string  | "success", "processing", or "error"    |
| `id`             | integer | Unique request identifier              |
| `output`         | array   | URLs of generated images               |
| `proxy_links`    | object  | CDN-optimized URLs for faster delivery |
| `generationTime` | float   | Time taken to generate (seconds)       |
| `meta`           | object  | Generation parameters used             |

## Tips for Better Results

<AccordionGroup>
  <Accordion title="Write Detailed Prompts">
    FLUX responds well to detailed, specific prompts. Include:

    * Subject description
    * Style (photorealistic, cinematic, etc.)
    * Lighting details
    * Camera settings (for photorealistic images)
  </Accordion>

  <Accordion title="Use Negative Prompts">
    Always include a negative prompt to avoid common issues:

    ```
    "blurry, low quality, distorted, deformed, ugly, bad anatomy"
    ```
  </Accordion>

  <Accordion title="Adjust Guidance Scale">
    * **Lower (3-7)**: More creative, varied results
    * **Higher (8-15)**: More literal prompt adherence
    * **Default (7.5)**: Good balance for most use cases
  </Accordion>
</AccordionGroup>

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Image to Image" icon="image" href="/image-generation/flux/flux-img2img">
    Transform existing images with FLUX
  </Card>

  <Card title="Fetch Results" icon="download" href="/image-generation/community-models/dreambooth-fetch-queue-image">
    Retrieve results for processing requests
  </Card>
</CardGroup>


## OpenAPI

````yaml POST /text2img
openapi: 3.1.0
info:
  title: ModelsLab Dreambooth Image Generation API
  description: >-
    A focused API for AI-driven image generation using Dreambooth models,
    including text-to-image, image-to-image, inpainting, and model management
    capabilities.
  license:
    name: MIT
  version: 6.0.0
servers:
  - url: https://modelslab.com/api/v6/images
    description: Dreambooth Image Generation API v6 server
security: []
paths:
  /text2img:
    post:
      summary: Text-to-Image
      description: >-
        Creates an image from a text prompt using Dreambooth models. This
        endpoint supports both single and multiple LoRA models for enhanced
        results.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TextToImageRequest'
      responses:
        '200':
          description: Text-to-image generation response
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ImageGenerationSuccessResponse'
                  - $ref: '#/components/schemas/ImageGenerationProcessingResponse'
                  - $ref: '#/components/schemas/ImageGenerationErrorResponse'
        '400':
          $ref: '#/components/responses/StandardErrorResponse'
        '401':
          $ref: '#/components/responses/StandardErrorResponse'
        '500':
          $ref: '#/components/responses/StandardErrorResponse'
components:
  schemas:
    TextToImageRequest:
      type: object
      allOf:
        - $ref: '#/components/schemas/CommonImageGenerationParams'
      required:
        - key
        - model_id
        - prompt
      properties:
        model_id:
          type: string
          description: >-
            The ID of the model to be used. It can be a public model or one you
            have trained.
        multi_lingual:
          type: boolean
          default: false
          description: >-
            Allow multilingual prompts. Set to 'true' if using a language other
            than English.
        upscale:
          type: boolean
          default: false
          description: Set to 'true' to upscale the image resolution two times (2x).
        highres_fix:
          type: boolean
          default: false
          description: Enable high-resolution fix for generated images.
    ImageGenerationSuccessResponse:
      type: object
      properties:
        status:
          type: string
          enum:
            - success
          description: Status of the image generation.
        generationTime:
          type: number
          description: Time taken to generate the image in seconds.
        id:
          type: integer
          description: Unique identifier for the image generation request.
        output:
          type: array
          items:
            type: string
            format: uri
          description: Array of generated image URLs.
        proxy_links:
          type: array
          items:
            type: string
            format: uri
          description: Array of proxy image URLs.
        meta:
          type: object
          description: Metadata about the image generation including all parameters used.
          additionalProperties: true
        nsfw_content_detected:
          type: boolean
          description: Indicates if NSFW content was detected in the generated image.
        webhook_status:
          type: string
          description: Status of the webhook notification.
        tip:
          type: string
          description: Additional information or tips for the user.
    ImageGenerationProcessingResponse:
      type: object
      properties:
        status:
          type: string
          enum:
            - processing
          description: Status of the image generation.
        tip:
          type: string
          description: Information about faster processing options.
        tip_1:
          type: string
          description: Additional tip, usually pointing to the fetch API.
        eta:
          type: number
          description: Estimated time for completion in seconds.
        message:
          type: string
          description: Processing status message.
        webhook_status:
          type: string
          description: Status of the webhook notification.
        fetch_result:
          type: string
          format: uri
          description: URL to fetch the result when processing.
        id:
          type: integer
          description: Unique identifier for the image generation request.
        output:
          type: array
          items:
            type: string
          description: Empty array during processing.
        meta:
          type: object
          description: Metadata about the image generation including all parameters used.
          additionalProperties: true
        future_links:
          type: array
          items:
            type: string
            format: uri
          description: Array of future image URLs for queued requests.
    ImageGenerationErrorResponse:
      type: object
      required:
        - status
        - message
      properties:
        status:
          type: string
          enum:
            - error
        message:
          type: string
          description: Error message description.
    CommonImageGenerationParams:
      type: object
      properties:
        key:
          type: string
          description: Your API Key used for request authorization.
        prompt:
          type: string
          description: A text description of what you want in the generated image.
        negative_prompt:
          type: string
          description: Items you don't want in the image.
        enhance_prompt:
          type: boolean
          default: 'yes'
          description: >-
            If true, the prompt will be enhanced for better results. Default is
            (true).
        width:
          type: integer
          default: 512
          maximum: 1024
          description: The width of the image in pixels.
        height:
          type: integer
          default: 512
          maximum: 1024
          description: The height of the image in pixels.
        samples:
          type: integer
          default: 1
          maximum: 4
          description: The number of images to be returned in response. Maximum is 4.
        num_inference_steps:
          type: integer
          default: 31
          minimum: 1
          maximum: 20
          description: >-
            The number of denoising steps. Values range from 1 to 20, and any
            value above 20 will be capped at 20.
        safety_checker:
          type: boolean
          default: false
          description: >-
            A checker for NSFW images. If detected, such images will be replaced
            by a blank image.
        safety_checker_type:
          $ref: '#/components/schemas/SafetyCheckerTypeEnum'
        seed:
          oneOf:
            - type: integer
            - type: 'null'
          description: >-
            Seed for reproducible results. The same seed generates the same
            image. Pass null for a random number.
        guidance_scale:
          type: number
          default: 7.5
          minimum: 1
          maximum: 20
          description: Scale for classifier-free guidance.
        use_karras_sigmas:
          type: boolean
          default: true
          description: Use Karras sigmas to generate images. Produces nice results.
        algorithm_type:
          type: string
          enum:
            - none
            - dpmsolver+++
          default: none
          description: Used in DPMSolverMultistepScheduler scheduler.
        vae:
          type: string
          nullable: true
          description: Use a custom VAE for generating images. Default is null.
        lora_strength:
          type: integer
          description: >-
            Strength of the LoRa model(s). If multiple LoRa models, provide
            comma-separated values (0.1 to 1).
        lora_model:
          type: string
          description: >-
            LoRa model ID(s). Multiple LoRa models are supported; pass
            comma-separated values (e.g., 'contrast-fix,yae-miko-genshin').
        clip_skip:
          type: integer
          default: 2
          minimum: 1
          maximum: 8
          description: Number of CLIP layers to skip.
        base64:
          type: boolean
          default: false
          description: >-
            If true, response output is base64 string. Input images can also be
            base64.
        temp:
          type: boolean
          default: false
          description: If true, stores image in temporary storage (cleaned every 24 hours).
        webhook:
          type: string
          format: uri
          description: URL to receive a POST API call once image generation is complete.
        track_id:
          type: string
          description: Unique ID used in webhook response to identify the request.
        ip_adapter_id:
          $ref: '#/components/schemas/IPAdapterIDEnum'
        ip_adapter_scale:
          type: number
          minimum: 0
          maximum: 1
          description: Scale for the IP adapter (0 to 1).
        ip_adapter_image:
          type: string
          format: uri
          description: Valid image URL for IP adapter.
        scheduler:
          $ref: '#/components/schemas/SchedulerEnum'
    SafetyCheckerTypeEnum:
      type: string
      enum:
        - blur
        - sensitive_content_text
        - pixelate
        - black
      default: sensitive_content_text
      description: How to modify the image if NSFW content is found.
    IPAdapterIDEnum:
      type: string
      enum:
        - ip-adapter_sdxl
        - ip-adapter_sd15
        - ip-adapter-plus-face_sd15
        - ip-adapter-plus_sdxl_vit-h
        - ip-adapter-plus-face_sdxl_vit-h
      description: IP adapter ID.
    SchedulerEnum:
      type: string
      enum:
        - DDPMScheduler
        - DDIMScheduler
        - PNDMScheduler
        - LMSDiscreteScheduler
        - EulerDiscreteScheduler
        - EulerAncestralDiscreteScheduler
        - DPMSolverMultistepScheduler
        - HeunDiscreteScheduler
        - KDPM2DiscreteScheduler
        - DPMSolverSinglestepScheduler
        - KDPM2AncestralDiscreteScheduler
        - UniPCMultistepScheduler
        - DDIMInverseScheduler
        - DEISMultistepScheduler
        - IPNDMScheduler
        - KarrasVeScheduler
        - ScoreSdeVeScheduler
        - LCMScheduler
      description: Available schedulers for image generation.
  responses:
    StandardErrorResponse:
      description: >-
        Bad request (invalid parameters), unauthorized (invalid API key), or
        internal server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ImageGenerationErrorResponse'

````