Hugging Face Image Generation API

Text-to-image generation

Documentation

Specifications

SDKs

Other Resources

OpenAPI Specification

hugging-face-image-generation-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: Hugging Face Dataset Viewer Audio Image Generation API
  description: Query and visualize datasets stored on the Hugging Face Hub through a lightweight REST API. Get dataset splits, preview rows, search and filter data, access Parquet files, retrieve size statistics, and obtain Croissant metadata - all without downloading the entire dataset.
  version: 1.0.0
  termsOfService: https://huggingface.co/terms-of-service
  contact:
    name: Hugging Face Support
    url: https://huggingface.co/support
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
servers:
- url: https://datasets-server.huggingface.co
  description: Hugging Face Dataset Viewer production server
security:
- {}
- bearerAuth: []
tags:
- name: Image Generation
  description: Text-to-image generation
paths:
  /v1/images/generations:
    post:
      summary: Generate Images
      description: Generate images from text prompts using diffusion models available through inference providers.
      operationId: createImageGeneration
      tags:
      - Image Generation
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageGenerationRequest'
            examples:
              CreateimagegenerationRequestExample:
                summary: Default createImageGeneration request
                x-microcks-default: true
                value:
                  model: example_value
                  prompt: example_value
                  n: 10
                  size: 256x256
                  response_format: url
                  negative_prompt: example_value
                  num_inference_steps: 10
                  guidance_scale: 42.5
      responses:
        '200':
          description: Generated images
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageGenerationResponse'
              examples:
                Createimagegeneration200Example:
                  summary: Default createImageGeneration 200 response
                  x-microcks-default: true
                  value:
                    created: 10
                    data:
                    - url: https://www.example.com
                      b64_json: example_value
                      revised_prompt: example_value
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Createimagegeneration400Example:
                  summary: Default createImageGeneration 400 response
                  x-microcks-default: true
                  value:
                    error:
                      message: example_value
                      type: example_value
                      code: example_value
      x-microcks-operation:
        delay: 0
        dispatcher: FALLBACK
components:
  schemas:
    ImageGenerationResponse:
      type: object
      properties:
        created:
          type: integer
          example: 10
        data:
          type: array
          items:
            type: object
            properties:
              url:
                type: string
                format: uri
                description: URL of the generated image
              b64_json:
                type: string
                description: Base64-encoded image data
              revised_prompt:
                type: string
                description: Revised prompt used for generation
          example: []
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: Error message
            type:
              type: string
              description: Error type
            code:
              type: string
              description: Error code
          example: example_value
    ImageGenerationRequest:
      type: object
      required:
      - model
      - prompt
      properties:
        model:
          type: string
          description: Image generation model ID
          example: stabilityai/stable-diffusion-xl-base-1.0
        prompt:
          type: string
          description: Text prompt describing the image to generate
          example: example_value
        n:
          type: integer
          minimum: 1
          maximum: 4
          default: 1
          description: Number of images to generate
          example: 10
        size:
          type: string
          description: Image dimensions
          enum:
          - 256x256
          - 512x512
          - 1024x1024
          default: 1024x1024
          example: 256x256
        response_format:
          type: string
          enum:
          - url
          - b64_json
          default: url
          example: url
        negative_prompt:
          type: string
          description: Negative prompt to guide generation
          example: example_value
        num_inference_steps:
          type: integer
          description: Number of diffusion steps
          example: 10
        guidance_scale:
          type: number
          format: float
          description: Classifier-free guidance scale
          example: 42.5
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: HF Token
      description: Optional Hugging Face API token. Required for private and gated datasets.