> ## 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

> Generate images fast with normal quality, where speed is more critical than high resolution.

<img src="https://mintcdn.com/mod/i8dYICFkuz1vpdrI/images/image-generation/realtime-stable-diffusion/assets/images/Realtime-Text-to-image-794d2b0546da382247ec0fd32988dc0f.jpg?fit=max&auto=format&n=i8dYICFkuz1vpdrI&q=85&s=b92cf037643885668c4797ed0a4386c6" alt="Text to image endpoint result" width="691" height="518" data-path="images/image-generation/realtime-stable-diffusion/assets/images/Realtime-Text-to-image-794d2b0546da382247ec0fd32988dc0f.jpg" />

<Note>
  This API currently supports the following image formats: **`PNG`** and **`JPG`**.
</Note>

## Request

Make a `POST` request to below endpoint and pass the required parameters as a request body.

```curl curl theme={null}
--request POST 'https://modelslab.com/api/v6/realtime/text2img' \
```

## Body

```json json theme={null}
{  
    "key": "your_api_key",  
    "prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))",  
    "negative_prompt": "bad quality",  
    "width": "512",  
    "height": "512",  
    "safety_checker": false,  
    "seed": null,  
    "samples": 1,  
    "base64": false,  
    "webhook": null,  
    "track_id": null
}
```


## OpenAPI

````yaml POST /realtime/text2img
openapi: 3.1.0
info:
  title: ModelsLab Real-Time Stable Diffusion API
  description: >-
    A comprehensive API for real-time AI-driven image generation, including
    text-to-image, image-to-image, inpainting, and fetching queued results.
  license:
    name: MIT
  version: 6.0.0
servers:
  - url: https://modelslab.com/api/v6
    description: Real-Time Stable Diffusion API v6 server
security: []
paths:
  /realtime/text2img:
    post:
      summary: Generate image from text prompt (Real-Time)
      description: >-
        Rapid image generation with standard quality from a text prompt. Ideal
        for applications where speed is more critical than high resolution.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RealtimeTextToImageRequest'
      responses:
        '200':
          description: Text-to-image generation response
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: >-
                      #/components/schemas/RealtimeImageGenerationSuccessResponse
                  - $ref: >-
                      #/components/schemas/RealtimeImageGenerationProcessingResponse
                  - $ref: '#/components/schemas/RealtimeImageGenerationErrorResponse'
        '400':
          $ref: '#/components/responses/StandardErrorResponse'
        '401':
          $ref: '#/components/responses/StandardErrorResponse'
        '500':
          $ref: '#/components/responses/StandardErrorResponse'
components:
  schemas:
    RealtimeTextToImageRequest:
      type: object
      allOf:
        - $ref: '#/components/schemas/RealtimeCommonImageGenerationParams'
      required:
        - key
        - prompt
    RealtimeImageGenerationSuccessResponse:
      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.
    RealtimeImageGenerationProcessingResponse:
      type: object
      properties:
        status:
          type: string
          enum:
            - processing
          description: Status of the image generation.
        tip:
          type: string
          description: Information about faster processing options.
        eta:
          type: number
          description: Estimated time for completion in seconds.
        message:
          type: string
          description: Processing status message.
        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.
    RealtimeImageGenerationErrorResponse:
      type: object
      required:
        - status
        - message
      properties:
        status:
          type: string
          enum:
            - error
        message:
          type: string
          description: Error message description.
    RealtimeCommonImageGenerationParams:
      type: object
      properties:
        key:
          type: string
          description: Your API Key used for request authorization.
        prompt:
          type: string
          description: >-
            Text prompt with description of the things you want in the image to
            be generated.
        negative_prompt:
          type: string
          description: Items you don't want in the image.
        width:
          type: integer
          default: 512
          maximum: 1024
          description: 'Width of the generated image in pixels. Max: 1024.'
        height:
          type: integer
          default: 512
          maximum: 1024
          description: 'Height of the generated image in pixels. Max: 1024.'
        samples:
          type: integer
          default: 1
          maximum: 4
          description: Number of images to be returned in response. Maximum value is 4.
        safety_checker:
          type: boolean
          default: false
          description: >-
            A checker for NSFW images. If such an image is detected, it will be
            replaced by a blank image.
        seed:
          oneOf:
            - type: integer
            - type: 'null'
          description: >-
            Seed is used to reproduce results; the same seed will give you the
            same image in return. Pass 'null' for a random number.
        instant_response:
          type: boolean
          default: false
          description: >-
            Queue response instantly before processing finishes instead of
            waiting a minimum amount of time.
        base64:
          type: boolean
          default: false
          description: Get response as base64 string.
        webhook:
          type: string
          format: uri
          description: URL to get a POST API call once the image generation is complete.
        track_id:
          type: string
          description: >-
            This ID is returned in the response to the webhook API call and is
            used to identify the webhook request.
  responses:
    StandardErrorResponse:
      description: >-
        Bad request (invalid parameters), unauthorized (invalid API key), or
        internal server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RealtimeImageGenerationErrorResponse'

````