Templated

SDKs & Libraries

Official and community client libraries for the Templated API.

SDKs & Libraries

We're building official client libraries to make integrating with Templated even easier.

Coming soon

LanguageStatusETA
Node.js / TypeScriptPlannedTBD
PythonPlannedTBD

Roll your own

In the meantime, the Templated API is a standard REST API that works with any HTTP client. Here's a minimal wrapper pattern:

JavaScript / TypeScript

class TemplatedClient {
  private baseUrl = "https://app.templated.email/api";
  private cookies: string;

  constructor(sessionCookie: string) {
    this.cookies = sessionCookie;
  }

  private async request(path: string, options?: RequestInit) {
    const response = await fetch(`${this.baseUrl}${path}`, {
      ...options,
      headers: {
        "Content-Type": "application/json",
        Cookie: this.cookies,
        ...options?.headers,
      },
    });

    if (!response.ok) {
      const error = await response.json();
      throw new Error(error.error || "API request failed");
    }

    return response.json();
  }

  async listTemplates(slug: string) {
    return this.request(`/accounts/${slug}/templates`);
  }

  async createTemplate(slug: string, data: { name: string; html?: string }) {
    return this.request(`/accounts/${slug}/templates`, {
      method: "POST",
      body: JSON.stringify(data),
    });
  }

  async generateWithAI(slug: string, prompt: string) {
    return this.request(`/accounts/${slug}/ai/generate`, {
      method: "POST",
      body: JSON.stringify({ prompt }),
    });
  }
}

Python

import requests

class TemplatedClient:
    def __init__(self, session_cookie: str):
        self.base_url = "https://app.templated.email/api"
        self.session = requests.Session()
        self.session.cookies.set("next-auth.session-token", session_cookie)

    def list_templates(self, slug: str):
        response = self.session.get(f"{self.base_url}/accounts/{slug}/templates")
        response.raise_for_status()
        return response.json()

    def create_template(self, slug: str, name: str, html: str = None):
        data = {"name": name}
        if html:
            data["html"] = html
        response = self.session.post(
            f"{self.base_url}/accounts/{slug}/templates",
            json=data,
        )
        response.raise_for_status()
        return response.json()

Contributing

Want to build a community library? We'd love to feature it here. Reach out at support@templated.email.

On this page