> ## 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.

# Introduction

> SendBetter API endpoints

SendBetter features an on-demand API to render templates designed in our image editor.

SendBetter API provides both authenticated and unauthenticated endpoints. The render endpoint can be used without authentication, while other endpoints require an API key.

<Card title="Render Image" icon="image" href="/api-reference/endpoint/render">
  Render a template image with dynamic data
</Card>

<Card title="Validate Organization" icon="check" href="/api-reference/endpoint/validate-organization">
  Validate your organization's API key
</Card>

<Card title="List Templates" icon="list" href="/api-reference/endpoint/templates">
  Get a list of all your templates
</Card>

<Card title="Get Template Details" icon="file" href="/api-reference/endpoint/template">
  Get detailed information about a specific template
</Card>

## Authentication

SendBetter API supports two authentication methods:

1. **Render Link** - No authentication required, perfect for public usage like email marketing or WhatsApp API
2. **API Key** - Required for accessing organization-specific endpoints. Pass your API key in the `X-API-Key` header

### Render Link

Render link is the most direct way to render a template.

Render link works based on [query parameters](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) to pass any dynamic data into a template. Modifications via query parameters will differ from template to template. To pass a dynamic content into a specific variable, make sure to you reference the variable with its name in the query parameters.

### API Key Authentication

For endpoints that require authentication, you need to include your API key in the `X-API-Key` header:

<CodeGroup>
  ```bash theme={null}
  curl -H "X-API-Key: your_api_key" https://api.sendbetter.co/v1/templates
  ```

  ```python theme={null}
  import requests

  headers = {
      'X-API-Key': 'your_api_key'
  }

  response = requests.get('https://api.sendbetter.co/v1/templates', headers=headers)
  ```

  ```javascript theme={null}
  fetch('https://api.sendbetter.co/v1/templates', {
    headers: {
      'X-API-Key': 'your_api_key'
    }
  })
  .then(response => response.json())
  .then(data => console.log(data));
  ```
</CodeGroup>

## Dynamic Variables

Variables inside a render link will differ from template to template due to dynamic modifications. While designing a template in the SendBetter image editor, you can define variables, which can be dynamically modified during the API call. To pass a dynamic content into a specific variable, make sure to you reference the variable with its name in the [query parameters](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams). Here's a breakdown of default behavior for passing in data to different types of variables.

| Variable Type | Description                                                                                                                  |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Text          | Dynamically updates text content                                                                                             |
| Image         | Dynamically updates image path. Must be a path to a publicly accessible image file. Google Drive public links are supported. |

## Example of dynamic modifications:

Note that variable names (text-variable-name etc.) are arbitrary and you need to use the corresponding names of variables in your template (you can name variables any way you want in our editor).

<CodeGroup>
  ```shell url.sh theme={null}
  https://api.sendbetter.co/v1/render/template_4my9GVvY1K1
      ?text-variable-name=Clint John
      &image-variable-name=https://unsplash.com/photos/3T-De1z7Jj8
  ```

  ```shell curl.sh theme={null}
  curl "https://api.sendbetter.co/v1/render/template_4my9GVvY1K1?text-variable-name=Clint%20John&image-variable-name=https://unsplash.com/photos/3T-De1z7Jj8" -o output.png
  ```

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

  # Variables
  name = "Clint John"
  imageSrc = "https://unsplash.com/photos/3T-De1z7Jj8"

  url = f"https://api.sendbetter.co/v1/render/template_4my9GVvY1K1?text-variable-name={name}&image-variable-name={imageSrc}"

  response = requests.get(url)
  with open("output.png", "wb") as f:
      f.write(response.content)
  ```

  ```javascript render.js theme={null}
  // Variables
  const name = "Clint John";
  const imageSrc = "https://unsplash.com/photos/3T-De1z7Jj8";

  const url = `https://api.sendbetter.co/v1/render/template_4my9GVvY1K1?text-variable-name=${name}&image-variable-name=${imageSrc}`;

  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>

## Rate limiting

Currently we do not rate limit our API. You can make as many requests as you want. However, we may change this in the future.

## Time to render

An image take take between 2 to 10 seconds to render. Depending on the size of the image and the complexity of the template, the time to render may vary.
