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

# Render Template

> Render a template with dynamic variables

This endpoint renders a template with the provided dynamic variables. The response is the rendered image file.

### Path Parameters

<ParamField path="uid" type="string" required>
  The unique identifier of the template to render
</ParamField>

### Query Parameters

<ParamField query="variables" type="object">
  An object containing key-value pairs of variable names and their values. The keys should match the variable names defined in the template.
</ParamField>

### Response

The endpoint returns the rendered image file directly. On success, you'll receive the image data with the appropriate content type header.

### Examples

Here's how to use the render endpoint with different variable types:

<CodeGroup>
  ```shell url.sh theme={null}
  # Basic text variable
  https://api.sendbetter.co/v1/render/template_abc123?text_headline=Welcome

  # Multiple variables
  https://api.sendbetter.co/v1/render/template_abc123
      ?text_headline=Welcome
      &image_logo=https://example.com/logo.png
  ```

  ```shell curl.sh theme={null}
  # Download rendered image
  curl "https://api.sendbetter.co/v1/render/template_abc123?text_headline=Welcome" -o output.png
  ```

  ```python render.py theme={null}
  import requests

  # Variables
  variables = {
      'text_headline': 'Welcome',
      'image_logo': 'https://example.com/logo.png'
  }

  # Build URL with query parameters
  template_id = 'template_abc123'
  base_url = f'https://api.sendbetter.co/v1/render/{template_id}'
  response = requests.get(base_url, params=variables)

  # Save the rendered image
  with open('output.png', 'wb') as f:
      f.write(response.content)
  ```

  ```javascript render.js theme={null}
  // Variables
  const variables = {
    text_headline: 'Welcome',
    image_logo: 'https://example.com/logo.png'
  };

  // Build URL with query parameters
  const templateId = 'template_abc123';
  const url = new URL(`https://api.sendbetter.co/v1/render/${templateId}`);
  Object.keys(variables).forEach(key => {
    url.searchParams.append(key, variables[key]);
  });

  // Download the rendered image
  fetch(url)
    .then(response => response.blob())
    .then(blob => {
      const url = URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = url;
      a.download = 'output.png';
      a.click();
    });
  ```
</CodeGroup>

### Error Responses

<CodeGroup>
  ```json Template Not Found theme={null}
  {
    "error": {
      "code": "NOT_FOUND",
      "message": "Template not found",
      "requestId": "req_abc123"
    }
  }
  ```

  ```json Invalid Variables theme={null}
  {
    "error": {
      "code": "BAD_REQUEST",
      "message": "Invalid variable value",
      "requestId": "req_xyz789"
    }
  }
  ```
</CodeGroup>


## OpenAPI

````yaml GET /v1/render/{uid}
openapi: 3.1.0
info:
  title: SendBetter API
  description: API to help you automate the creation of personalized images at scale
  version: v1
servers: []
security: []
paths:
  /v1/render/{uid}:
    get:
      parameters:
        - in: path
          name: uid
          required: true
          schema:
            type: string
            description: The unique identifier of the template
        - in: query
          name: variables
          required: false
          schema:
            type: object
            additionalProperties:
              type: string
            description: Dynamic variables for the template
      responses:
        '200':
          description: The dynamically rendered image
        '400':
          description: >-
            The server cannot or will not process the request due to something
            that is perceived to be a client error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrBadRequest'
        '401':
          description: Authentication is required to access this resource.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrUnauthorized'
        '404':
          description: The requested template could not be found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrNotFound'
components:
  schemas:
    ErrBadRequest:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - BAD_REQUEST
              description: A machine readable error code.
              example: BAD_REQUEST
            message:
              type: string
              description: A human readable explanation of what went wrong
            requestId:
              type: string
              description: Please always include the requestId in your error report
              example: req_1234
          required:
            - code
            - message
            - requestId
      required:
        - error
    ErrUnauthorized:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - UNAUTHORIZED
              description: A machine readable error code.
              example: UNAUTHORIZED
            message:
              type: string
              description: A human readable explanation of what went wrong
            requestId:
              type: string
              description: Please always include the requestId in your error report
              example: req_1234
          required:
            - code
            - message
            - requestId
      required:
        - error
    ErrNotFound:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - NOT_FOUND
              description: A machine readable error code.
              example: NOT_FOUND
            message:
              type: string
              description: A human readable explanation of what went wrong
            requestId:
              type: string
              description: Please always include the requestId in your error report
              example: req_1234
          required:
            - code
            - message
            - requestId
      required:
        - error

````