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

# Generate an HTML block

> Generates a self-contained interactive HTML widget — a calculator, dashboard, slide deck, prototype or game — for an editor HTML block, or revises one when `currentHtml` is given. The widget follows HERO's design system and is responsive. Context comes from the page (`context`), references in the prompt, picked `mentions` and `attachments`.

The response streams as Server-Sent Events: `delta` events carry raw model output as it is written, then one `done` event carries the finished HTML (or an `error` event). Validation, plan and quota failures are answered as JSON before any stream starts. Insert the result with `write_document_markdown` as an ` ```html-block ` fence, or store it with `POST /media/html` and set the returned `_id` as an `htmlBlock` node's `resourceId`.



## OpenAPI

````yaml post /ai-agent/generate-html
openapi: 3.1.0
info:
  title: HERO API
  version: current
  description: |-
    The HERO REST API.

    See https://developers.myhero.so for the rendered docs.
servers:
  - url: https://app.myhero.so
security: []
paths:
  /ai-agent/generate-html:
    post:
      tags:
        - AI
      summary: Generate an HTML block
      description: >-
        Generates a self-contained interactive HTML widget — a calculator,
        dashboard, slide deck, prototype or game — for an editor HTML block, or
        revises one when `currentHtml` is given. The widget follows HERO's
        design system and is responsive. Context comes from the page
        (`context`), references in the prompt, picked `mentions` and
        `attachments`.


        The response streams as Server-Sent Events: `delta` events carry raw
        model output as it is written, then one `done` event carries the
        finished HTML (or an `error` event). Validation, plan and quota failures
        are answered as JSON before any stream starts. Insert the result with
        `write_document_markdown` as an ` ```html-block ` fence, or store it
        with `POST /media/html` and set the returned `_id` as an `htmlBlock`
        node's `resourceId`.
      operationId: aiGenerateHtmlBlock
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                prompt:
                  type: string
                  minLength: 1
                  maxLength: 4000
                model:
                  type: string
                currentHtml:
                  type: string
                context:
                  type: object
                  properties:
                    title:
                      type: string
                      maxLength: 300
                    text:
                      type: string
                      maxLength: 20000
                mentions:
                  type: array
                  items:
                    type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - document
                          - file
                          - folder
                          - table
                          - column
                          - project
                          - workspace
                          - clause
                          - term
                      id:
                        type: string
                        minLength: 1
                      name:
                        type: string
                        maxLength: 300
                      extra:
                        type: object
                        additionalProperties:
                          type: string
                          maxLength: 300
                    required:
                      - type
                      - id
                      - name
                attachments:
                  type: array
                  items:
                    type: object
                    properties:
                      filename:
                        type: string
                      mimeType:
                        type: string
                      base64:
                        type: string
                      size:
                        type: number
                        minimum: 0
                    required:
                      - filename
                      - mimeType
                      - base64
                      - size
              required:
                - prompt
      responses:
        '200':
          description: SSE stream of GenerateHtmlBlockEvent events
          content:
            text/event-stream:
              schema:
                type: object
                properties:
                  type:
                    type: string
                    enum:
                      - delta
                      - done
                      - error
                  text:
                    type: string
                  html:
                    type: string
                  message:
                    type: string
                required:
                  - type
        '400':
          description: >-
            Invalid request (missing prompt, too many mentions or attachments,
            `currentHtml` too long).
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '401':
          description: Not signed in.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '403':
          description: Attachments without a plan that includes them.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '429':
          description: AI usage limit reached, or the plan has no AI.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: HERO personal access token

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.