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

# Apply a template

> Apply a template to a canvas as a single collapsed box.

Each `inputs` entry targets a template `portId` (from **List templates**) and is one of `text`, `asset` (a stored library asset id), or `assetUrl` (a remote media URL that Melius fetches and stores as an asset — **Beta**, API-key requests only). The request sample on the right shows an `asset` input; to pass a **media URL** instead, send an `assetUrl` input:

```bash
curl --request POST \
  --url https://api.melius.com/api/v1/templates/apply \
  --header 'Authorization: Bearer <mel_api_key>' \
  --header 'Content-Type: application/json' \
  --header 'x-team-id: <team-id>' \
  --data '{
  "canvasId": "<canvasId>",
  "templateId": "<templateId>",
  "inputs": [
    { "kind": "assetUrl", "portId": "<portId>", "url": "https://example.com/photo.jpg", "mediaType": "image" }
  ]
}'
```



## OpenAPI

````yaml /api/openapi.json post /api/v1/templates/apply
openapi: 3.0.2
info:
  title: Melius API
  version: '1'
  description: >-
    The Melius REST API. Authenticate with an API key as a bearer token
    (`Authorization: Bearer mel_...`) and select the team to act on with the
    `x-team-id` header. Generations run through the same node + run pipeline as
    the app: create a node on a canvas, start a run, poll the run, then read the
    resulting version asset.
servers:
  - url: https://api.melius.com
security:
  - apiKey: []
    teamId: []
paths:
  /api/v1/templates/apply:
    post:
      tags:
        - template
      summary: Apply a template
      description: >-
        Apply a template to a canvas as a single collapsed box.


        Each `inputs` entry targets a template `portId` (from **List
        templates**) and is one of `text`, `asset` (a stored library asset id),
        or `assetUrl` (a remote media URL that Melius fetches and stores as an
        asset — **Beta**, API-key requests only). The request sample on the
        right shows an `asset` input; to pass a **media URL** instead, send an
        `assetUrl` input:


        ```bash

        curl --request POST \
          --url https://api.melius.com/api/v1/templates/apply \
          --header 'Authorization: Bearer <mel_api_key>' \
          --header 'Content-Type: application/json' \
          --header 'x-team-id: <team-id>' \
          --data '{
          "canvasId": "<canvasId>",
          "templateId": "<templateId>",
          "inputs": [
            { "kind": "assetUrl", "portId": "<portId>", "url": "https://example.com/photo.jpg", "mediaType": "image" }
          ]
        }'

        ```
      operationId: template.apply
      parameters: []
      requestBody:
        description: Body
        content:
          application/json:
            schema:
              type: object
              properties:
                canvasId:
                  type: string
                  format: uuid
                templateId:
                  type: string
                  format: uuid
                centerX:
                  type: number
                centerY:
                  type: number
                inputs:
                  type: array
                  items:
                    oneOf:
                      - type: object
                        properties:
                          kind:
                            type: string
                            enum:
                              - asset
                          portId:
                            type: string
                          assetId:
                            type: string
                            format: uuid
                          mediaType:
                            type: string
                            enum:
                              - image
                              - video
                              - audio
                              - pdf
                        required:
                          - kind
                          - portId
                          - assetId
                          - mediaType
                      - type: object
                        properties:
                          kind:
                            type: string
                            enum:
                              - text
                          portId:
                            type: string
                          text:
                            type: string
                            minLength: 1
                        required:
                          - kind
                          - portId
                          - text
                      - type: object
                        properties:
                          kind:
                            type: string
                            enum:
                              - assetUrl
                          portId:
                            type: string
                          url:
                            type: string
                            format: uri
                          mediaType:
                            type: string
                            enum:
                              - image
                              - video
                              - audio
                              - pdf
                        required:
                          - kind
                          - portId
                          - url
                          - mediaType
              required:
                - canvasId
                - templateId
      responses:
        '200':
          description: '200'
          content:
            application/json:
              schema:
                type: object
                properties:
                  instanceId:
                    type: string
                  groupId:
                    type: string
                required:
                  - instanceId
                  - groupId
        '401':
          description: Missing, invalid, expired, or revoked API key.
          content:
            application/json:
              schema:
                type: object
                properties:
                  statusCode:
                    type: integer
                  error:
                    type: string
                  message:
                    type: string
                required:
                  - statusCode
                  - message
        '403':
          description: The API key's user is not a member of the requested team.
          content:
            application/json:
              schema:
                type: object
                properties:
                  statusCode:
                    type: integer
                  error:
                    type: string
                  message:
                    type: string
                required:
                  - statusCode
                  - message
        '404':
          description: '404'
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                required:
                  - message
        '429':
          description: Rate limit reached — retry after the `Retry-After` header.
          headers:
            Retry-After:
              description: Seconds to wait before retrying.
              schema:
                type: integer
          content:
            application/json:
              schema:
                type: object
                properties:
                  statusCode:
                    type: integer
                  error:
                    type: string
                  message:
                    type: string
                  retryAfterSeconds:
                    type: integer
                required:
                  - statusCode
                  - message
components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: 'A Melius API key (`mel_...`), sent as `Authorization: Bearer <key>`.'
    teamId:
      type: apiKey
      in: header
      name: x-team-id
      description: The team (workspace) to act on. Defaults to the key's team when omitted.

````