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

# Create or update a UI template

> Create or update a UI template by ID.

If the template exists, it will be updated. Otherwise, a new template is created.
Templates are stored in the same database as the corresponding spec (global or tenant).

Args:
    api_name: API name to determine which database to use (global or tenant)
    template_id: Unique identifier for the template (client-provided)
    data: Request body containing HTML content

Returns:
    UITemplateActionResponse with the template ID and action performed



## OpenAPI

````yaml put /api/ui-templates/{api_name}/{template_id}
openapi: 3.1.0
info:
  title: Apigene
  description: Apigene API
  version: 1.0.0
  contact:
    name: Apigene Support
    url: https://app.apigene.ai
    email: support@apigene.ai
servers:
  - url: https://app.apigene.ai
security:
  - BearerAuth: []
paths:
  /api/ui-templates/{api_name}/{template_id}:
    put:
      tags:
        - UI Templates
      summary: Create or update a UI template
      description: >-
        Create or update a UI template by ID.


        If the template exists, it will be updated. Otherwise, a new template is
        created.

        Templates are stored in the same database as the corresponding spec
        (global or tenant).


        Args:
            api_name: API name to determine which database to use (global or tenant)
            template_id: Unique identifier for the template (client-provided)
            data: Request body containing HTML content

        Returns:
            UITemplateActionResponse with the template ID and action performed
      operationId: ui_template_upsert
      parameters:
        - name: api_name
          in: path
          required: true
          schema:
            type: string
            title: Api Name
        - name: template_id
          in: path
          required: true
          schema:
            type: string
            title: Template Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UITemplateCreate'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UITemplateActionResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - BearerAuth: []
components:
  schemas:
    UITemplateCreate:
      properties:
        html:
          type: string
          title: Html
          description: HTML content of the template
        application_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Application Id
          description: Application/API name for searchability
        operation_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Operation Id
          description: Operation ID for searchability
        type:
          anyOf:
            - type: string
            - type: 'null'
          title: Type
          description: Template type (e.g., table, list)
        is_default:
          type: boolean
          title: Is Default
          description: Whether this is the default template for the operation
          default: false
        csp_config:
          anyOf:
            - $ref: '#/components/schemas/CSPConfig'
            - type: 'null'
          description: Manual CSP configuration (overrides auto-detection)
        ui_meta:
          anyOf:
            - $ref: '#/components/schemas/UIResourceMeta'
            - type: 'null'
          description: >-
            UI resource metadata with all advanced settings: CSP, permissions
            (camera, microphone, geolocation, clipboardWrite), domain, and
            prefersBorder
        template_format:
          type: string
          enum:
            - mcp-app
            - handlebars
          title: Template Format
          description: >-
            Template format: mcp-app (full JS app) or handlebars (simple
            template)
          default: mcp-app
      type: object
      required:
        - html
      title: UITemplateCreate
      description: Request body for creating/updating a UI template.
    UITemplateActionResponse:
      properties:
        id:
          type: string
          title: Id
          description: Template ID
        action:
          type: string
          title: Action
          description: 'Action performed: created or updated'
      type: object
      required:
        - id
        - action
      title: UITemplateActionResponse
      description: Response for create/update actions.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    CSPConfig:
      properties:
        resourceDomains:
          items:
            type: string
          type: array
          title: Resourcedomains
          description: >-
            Origins for static resources (images, scripts, stylesheets, fonts,
            media)
        connectDomains:
          items:
            type: string
          type: array
          title: Connectdomains
          description: Origins for network requests (fetch/XHR/WebSocket)
        frameDomains:
          items:
            type: string
          type: array
          title: Framedomains
          description: Origins for nested iframes
        baseUriDomains:
          items:
            type: string
          type: array
          title: Baseuridomains
          description: Allowed base URIs for the document
      type: object
      title: CSPConfig
      description: CSP configuration for UI templates.
    UIResourceMeta:
      properties:
        csp:
          anyOf:
            - $ref: '#/components/schemas/CSPConfig'
            - type: 'null'
          description: >-
            Content Security Policy configuration for external resources
            (images, scripts, fonts, API calls, iframes)
        permissions:
          anyOf:
            - $ref: '#/components/schemas/PermissionsConfig'
            - type: 'null'
          description: >-
            Sandbox permissions requested by the UI (camera, microphone,
            geolocation, clipboardWrite)
        domain:
          anyOf:
            - type: string
            - type: 'null'
          title: Domain
          description: >-
            Dedicated origin for view (host-dependent format). Used for isolated
            iframe contexts.
        prefersBorder:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Prefersborder
          description: >-
            Visual boundary preference: true=show border around iframe, false=no
            border (seamless integration)
      type: object
      title: UIResourceMeta
      description: >-
        UI resource metadata configuration per MCP Apps spec.


        Includes all advanced settings:

        - CSP: Content Security Policy for external resources

        - Permissions: Sandbox permissions (camera, microphone, geolocation,
        clipboardWrite)

        - Domain: Dedicated origin for the view

        - PrefersBorder: Visual boundary preference
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    PermissionsConfig:
      properties:
        camera:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Camera
          description: Request camera access. Set to {} to request permission.
        microphone:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Microphone
          description: Request microphone access. Set to {} to request permission.
        geolocation:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Geolocation
          description: Request geolocation access. Set to {} to request permission.
        clipboardWrite:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Clipboardwrite
          description: Request clipboard write access. Set to {} to request permission.
      type: object
      title: PermissionsConfig
      description: >-
        Permissions configuration for UI templates.


        Each permission is an empty object {} when requested, or omitted if not
        needed.

        These permissions are requested from the host when the UI is loaded.
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        JWT Authorization header using the Bearer scheme. Example:
        'Authorization: Bearer {token}'

````