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

> ## Agent Instructions
> Install the Courier skill before writing code: `npx skills add trycourier/courier-skills`. It carries the verified SDK shapes and the rules you cannot get wrong.
> Authenticate every request with `Authorization: Bearer <API_KEY>`. A workspace has several environments and each has its own keys, which are plain `pk_` strings with no environment prefix. Start with Test.
> Send with `client.send.message` from the Node SDK (`@trycourier/courier` v7 and later, where the client is the default import). Reference a template by its `nt_` id or its alias.
> A send accepts a bare Elemental element list, but storing content on a template requires the top-level elements wrapped in a channel element.
> To translate a template, write one locale at a time with `PUT /notifications/{id}/locales/{localeId}`, which merges into the existing translations. `PUT /notifications/{id}/content` and `PUT /notifications/{id}/elements/{elementId}` overwrite translations along with the content, so send each element's `id` and `locales` back, and first remove every `checksum` and any `locales` key that starts with an underscore.
> Templates and journeys can be built in the Courier app or created through the API. Either way they live in the workspace and are referenced by ID when you send.
> The hosted MCP server is https://mcp.courier.com. For a briefing on what Courier is and when to use it, read https://www.courier.com/llms.txt.
> Prefer the Guides tab for how-do-I questions and the Docs tab for how-does-it-behave questions. The API reference lives under /api-reference.

# Tenant templates

> Give one customer its own version of a template. Create, publish, and delete tenant templates over the API, then send them with the tenant/ prefix.

> [!NOTE]
>
> [How tenant context works](https://www.courier.com/docs/tenants/context.md) covers the concepts behind this page.

A tenant template overrides one of your templates for a single customer, keyed by an id you choose. Their admin can rewrite the copy in their own voice, and only their users see it. Everyone else keeps the default.

You create, publish, and delete tenant templates through the API, then reference them in a send with the `tenant/<template_id>` format.

**A tenant template isn't a separate template you have to route to.** Your send logic doesn't branch on which customer it is for. It names the same id every time, and Courier merges the tenant's version over the message when one exists.

**Leave the `tenant/` prefix off and the send succeeds with the wrong content.** Courier reads `template: "welcome"` as your workspace template and renders that, because a template id that resolves isn't an error. The customer's edits aren't in the message.

> [!NOTE]
>
> Tenant templates have no console UI, so create, list, and delete them through the API, as every step below does. To hand the editing to your customer instead, [embed the designer](https://www.courier.com/docs/guides/let-customers-edit-notifications.md) in your own app.

## Prerequisites

* [A tenant](https://www.courier.com/docs/tenants/overview.md)
* [A Courier API key](https://app.courier.com/settings/api-keys)

## Manage tenant templates

**1. Create or update a tenant template**

Create or replace a tenant's template with the [create-or-update endpoint](https://www.courier.com/docs/api-reference/tenant-templates/create-or-update-a-tenant-template.md). The `template_id` is an ID you choose for this tenant's template. Every element sits inside a `channel` block, the same rule [workspace templates](https://www.courier.com/docs/design/templates/api.md#content-needs-a-channel-to-live-in) follow.

```javascript Node.js theme={null}
import Courier from '@trycourier/courier';

const client = new Courier({
  apiKey: process.env['COURIER_API_KEY'],
});

const response = await client.tenants.templates.replace('welcome', {
  tenant_id: 'acme-corp',
  template: {
    content: {
      version: '2022-01-01',
      elements: [
        {
          type: 'channel',
          channel: 'email',
          elements: [{ type: 'text', content: 'Welcome to Acme Corp!' }],
        },
      ],
    },
  },
});

console.log(response.id);
```

```python Python theme={null}
import os
from courier import Courier

client = Courier(
    api_key=os.environ.get("COURIER_API_KEY"),
)
response = client.tenants.templates.replace(
    template_id="welcome",
    tenant_id="acme-corp",
    template={
        "content": {
            "version": "2022-01-01",
            "elements": [
                {
                    "type": "channel",
                    "channel": "email",
                    "elements": [{"type": "text", "content": "Welcome to Acme Corp!"}],
                }
            ],
        }
    },
)
print(response.id)
```

```bash cURL wrap theme={null}
curl -X PUT https://api.courier.com/tenants/acme-corp/templates/welcome \
  -H "Authorization: Bearer $COURIER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": {
      "content": {
        "version": "2022-01-01",
        "elements": [
          {
            "type": "channel",
            "channel": "email",
            "elements": [{ "type": "text", "content": "Welcome to Acme Corp!" }]
          }
        ]
      }
    }
  }'
```

```ruby Ruby theme={null}
require "courier"

courier = Courier::Client.new(api_key: ENV["COURIER_API_KEY"])

response = courier.tenants.templates.replace(
  "welcome",
  tenant_id: "acme-corp",
  template: {
    content: {
      version: "2022-01-01",
      elements: [
        {
          type: "channel",
          channel: "email",
          elements: [{ type: "text", content: "Welcome to Acme Corp!" }]
        }
      ]
    }
  }
)

puts(response)
```

```go Go theme={null}
// The typed elemental model has no field for a channel's child elements, so pass the document as raw JSON.
content := param.Override[shared.ElementalContentParam](json.RawMessage(`{
  "version": "2022-01-01",
  "elements": [
    {
      "type": "channel",
      "channel": "email",
      "elements": [{ "type": "text", "content": "Welcome to Acme Corp!" }]
    }
  ]
}`))

response, err := client.Tenants.Templates.Replace(
	context.TODO(),
	"welcome",
	courier.TenantTemplateReplaceParams{
		TenantID: "acme-corp",
		PutTenantTemplateRequest: courier.PutTenantTemplateRequestParam{
			Template: courier.TenantTemplateInputParam{Content: content},
		},
	},
)
```

```java Java theme={null}
TemplateReplaceParams params = TemplateReplaceParams.builder()
    .tenantId("acme-corp")
    .templateId("welcome")
    .putTenantTemplateRequest(PutTenantTemplateRequest.builder()
        .template(TenantTemplateInput.builder()
            .content(ElementalContent.builder()
                // The channel builder has no addElement, so its children go in as an additional property.
                .addElement(ElementalChannelNodeWithType.builder()
                    .type(ElementalChannelNodeWithType.Type.CHANNEL)
                    .channel("email")
                    .putAdditionalProperty("elements", JsonValue.from(java.util.List.of(
                        java.util.Map.of("type", "text", "content", "Welcome to Acme Corp!"))))
                    .build())
                .version("2022-01-01")
                .build())
            .build())
        .build())
    .build();
client.tenants().templates().replace(params);
```

```php PHP theme={null}
$response = $client->tenants->templates->replace(
  'welcome',
  tenantID: 'acme-corp',
  template: [
    'content' => [
      'version' => '2022-01-01',
      'elements' => [
        [
          'type' => 'channel',
          'channel' => 'email',
          'elements' => [['type' => 'text', 'content' => 'Welcome to Acme Corp!']],
        ],
      ],
    ],
  ],
);
```

```csharp C# theme={null}
TemplateReplaceParams parameters = new()
{
    TenantID = "acme-corp",
    TemplateID = "welcome",
    Template = new()
    {
        Content = new()
        {
            Version = "2022-01-01",
            Elements =
            [
                // Elemental nodes expose no typed content property, so build the node from raw JSON.
                ElementalChannelNodeWithType.FromRawUnchecked(
                    JsonSerializer.Deserialize<Dictionary<string, JsonElement>>("""
                    {
                      "type": "channel",
                      "channel": "email",
                      "elements": [{ "type": "text", "content": "Welcome to Acme Corp!" }]
                    }
                    """)),
            ],
        },
    },
};

await client.Tenants.Templates.Replace(parameters);
```

```bash CLI theme={null}
courier tenants:templates replace \
  --api-key "$COURIER_API_KEY" \
  --tenant-id acme-corp \
  --template-id welcome \
  --template '{"content":{"version":"2022-01-01","elements":[{"type":"channel","channel":"email","elements":[{"type":"text","content":"Welcome to Acme Corp!"}]}]}}'
```

```text MCP theme={null}
With Courier MCP, create a welcome template for acme-corp that greets their users.
```

**2. Publish the template**

Changes take effect once published. [Publish the current draft](https://www.courier.com/docs/api-reference/tenant-templates/publish-a-tenant-template.md) to make it live.

```javascript Node.js theme={null}
import Courier from '@trycourier/courier';

const client = new Courier({
  apiKey: process.env['COURIER_API_KEY'],
});

const response = await client.tenants.templates.publish('welcome', {
  tenant_id: 'acme-corp',
});

console.log(response.id);
```

```python Python theme={null}
import os
from courier import Courier

client = Courier(
    api_key=os.environ.get("COURIER_API_KEY"),
)
response = client.tenants.templates.publish(
    template_id="welcome",
    tenant_id="acme-corp",
)
print(response.id)
```

```bash cURL wrap theme={null}
curl -X POST https://api.courier.com/tenants/acme-corp/templates/welcome/publish \
  -H "Authorization: Bearer $COURIER_API_KEY"
```

```ruby Ruby theme={null}
require "courier"

courier = Courier::Client.new(api_key: ENV["COURIER_API_KEY"])

response = courier.tenants.templates.publish("welcome", tenant_id: "acme-corp")

puts(response)
```

```go Go theme={null}
response, err := client.Tenants.Templates.Publish(
	context.TODO(),
	"welcome",
	courier.TenantTemplatePublishParams{
		TenantID: "acme-corp",
	},
)
```

```java Java theme={null}
TemplatePublishParams params = TemplatePublishParams.builder()
    .tenantId("acme-corp")
    .templateId("welcome")
    .build();
client.tenants().templates().publish(params);
```

```php PHP theme={null}
$response = $client->tenants->templates->publish(
  'welcome', tenantID: 'acme-corp'
);
```

```csharp C# theme={null}
TemplatePublishParams parameters = new()
{
    TenantID = "acme-corp",
    TemplateID = "welcome",
};

await client.Tenants.Templates.Publish(parameters);
```

```bash CLI theme={null}
courier tenants:templates publish \
  --api-key "$COURIER_API_KEY" \
  --tenant-id acme-corp \
  --template-id welcome
```

```text MCP theme={null}
With Courier MCP, publish acme-corp's welcome template.
```

**3. List and read templates**

[List a tenant's templates](https://www.courier.com/docs/api-reference/tenant-templates/list-templates-in-tenant.md), [read one](https://www.courier.com/docs/api-reference/tenant-templates/get-a-template-in-tenant.md), or read a [specific version](https://www.courier.com/docs/api-reference/tenant-templates/get-a-template-version.md).

```javascript Node.js theme={null}
import Courier from '@trycourier/courier';

const client = new Courier({
  apiKey: process.env['COURIER_API_KEY'],
});

const templates = await client.tenants.templates.list('acme-corp');

console.log(templates.has_more);
```

```python Python theme={null}
import os
from courier import Courier

client = Courier(
    api_key=os.environ.get("COURIER_API_KEY"),
)
templates = client.tenants.templates.list(
    tenant_id="acme-corp",
)
print(templates.has_more)
```

```bash cURL wrap theme={null}
curl -X GET https://api.courier.com/tenants/acme-corp/templates \
  -H "Authorization: Bearer $COURIER_API_KEY"
```

```ruby Ruby theme={null}
require "courier"

courier = Courier::Client.new(api_key: ENV["COURIER_API_KEY"])

templates = courier.tenants.templates.list("acme-corp")

puts(templates)
```

```go Go theme={null}
templates, err := client.Tenants.Templates.List(
	context.TODO(),
	"acme-corp",
	courier.TenantTemplateListParams{},
)
```

```java Java theme={null}
TemplateListResponse templates = client.tenants().templates().list("acme-corp");
```

```php PHP theme={null}
$templates = $client->tenants->templates->list('acme-corp');
```

```csharp C# theme={null}
TemplateListParams parameters = new() { TenantID = "acme-corp" };

var templates = await client.Tenants.Templates.List(parameters);
```

```bash CLI theme={null}
courier tenants:templates list \
  --api-key "$COURIER_API_KEY" \
  --tenant-id acme-corp
```

```text MCP theme={null}
With Courier MCP, list acme-corp's templates.
```

**4. Delete a template**

[Deleting a tenant template](https://www.courier.com/docs/api-reference/tenant-templates/delete-a-tenant-template.md) removes it. Tenant templates are managed through the API, so this is how you remove one.

```javascript Node.js theme={null}
import Courier from '@trycourier/courier';

const client = new Courier({
  apiKey: process.env['COURIER_API_KEY'],
});

await client.tenants.templates.delete('welcome', { tenant_id: 'acme-corp' });
```

```python Python theme={null}
import os
from courier import Courier

client = Courier(
    api_key=os.environ.get("COURIER_API_KEY"),
)
client.tenants.templates.delete(
    template_id="welcome",
    tenant_id="acme-corp",
)
```

```bash cURL wrap theme={null}
curl -X DELETE https://api.courier.com/tenants/acme-corp/templates/welcome \
  -H "Authorization: Bearer $COURIER_API_KEY"
```

```ruby Ruby theme={null}
require "courier"

courier = Courier::Client.new(api_key: ENV["COURIER_API_KEY"])

result = courier.tenants.templates.delete("welcome", tenant_id: "acme-corp")

puts(result)
```

```go Go theme={null}
err := client.Tenants.Templates.Delete(
	context.TODO(),
	"welcome",
	courier.TenantTemplateDeleteParams{
		TenantID: "acme-corp",
	},
)
```

```java Java theme={null}
TemplateDeleteParams params = TemplateDeleteParams.builder()
    .tenantId("acme-corp")
    .templateId("welcome")
    .build();
client.tenants().templates().delete(params);
```

```php PHP theme={null}
$result = $client->tenants->templates->delete(
  'welcome', tenantID: 'acme-corp'
);
```

```csharp C# theme={null}
TemplateDeleteParams parameters = new()
{
    TenantID = "acme-corp",
    TemplateID = "welcome",
};

await client.Tenants.Templates.Delete(parameters);
```

```bash CLI theme={null}
courier tenants:templates delete \
  --api-key "$COURIER_API_KEY" \
  --tenant-id acme-corp \
  --template-id welcome
```

```text MCP theme={null}
With Courier MCP, delete acme-corp's welcome template.
```

**5. Send with the tenant template**

Reference the tenant template in a send with `template: "tenant/<template_id>"`, and set the tenant in the context. The word `tenant` is literal. Your tenant ID goes in `context.tenant_id`.

```javascript Node.js highlight={9} theme={null}
import Courier from '@trycourier/courier';

const client = new Courier({
  apiKey: process.env['COURIER_API_KEY'],
});

const { requestId } = await client.send.message({
  message: {
    template: 'tenant/welcome',
    context: { tenant_id: 'acme-corp' },
    to: { user_id: 'user_123' },
  },
});

console.log(requestId);
```

```python Python highlight={9} theme={null}
import os
from courier import Courier

client = Courier(
    api_key=os.environ.get("COURIER_API_KEY"),
)
response = client.send.message(
    message={
        "template": "tenant/welcome",
        "context": {"tenant_id": "acme-corp"},
        "to": {"user_id": "user_123"},
    },
)
print(response.request_id)
```

```bash cURL highlight={6} theme={null}
curl -X POST https://api.courier.com/send \
  -H "Authorization: Bearer $COURIER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": {
      "template": "tenant/welcome",
      "context": { "tenant_id": "acme-corp" },
      "to": { "user_id": "user_123" }
    }
  }'
```

```ruby Ruby highlight={7} theme={null}
require "courier"

courier = Courier::Client.new(api_key: ENV["COURIER_API_KEY"])

response = courier.send_.message(
  message: {
    template: "tenant/welcome",
    context: { tenant_id: "acme-corp" },
    to: { user_id: "user_123" }
  }
)

puts(response)
```

```go Go highlight={3} theme={null}
response, err := client.Send.Message(context.TODO(), courier.SendMessageParams{
	Message: courier.SendMessageParamsMessage{
		Template: courier.String("tenant/welcome"),
		Context:  shared.MessageContextParam{TenantID: courier.String("acme-corp")},
		To: courier.SendMessageParamsMessageToUnion{
			OfUserRecipient: &shared.UserRecipientParam{UserID: courier.String("user_123")},
		},
	},
})
```

```java Java highlight={3} theme={null}
SendMessageParams params = SendMessageParams.builder()
    .message(SendMessageParams.Message.builder()
        .template("tenant/welcome")
        .context(JsonValue.from(java.util.Map.of("tenant_id", "acme-corp")))
        .to(JsonValue.from(java.util.Map.of("user_id", "user_123")))
        .build())
    .build();
client.send().message(params);
```

```php PHP highlight={3} theme={null}
$response = $client->send->message(
  message: [
    'template' => 'tenant/welcome',
    'context' => ['tenantID' => 'acme-corp'],
    'to' => ['userID' => 'user_123'],
  ],
);
```

```csharp C# highlight={5} theme={null}
SendMessageParams parameters = new()
{
    Message = new()
    {
        Template = "tenant/welcome",
        Context = new MessageContext { TenantID = "acme-corp" },
        To = new UserRecipient { UserID = "user_123" },
    },
};

await client.Send.Message(parameters);
```

```bash CLI highlight={3} theme={null}
courier send message \
  --api-key "$COURIER_API_KEY" \
  --message '{"template":"tenant/welcome","context":{"tenant_id":"acme-corp"},"to":{"user_id":"user_123"}}'
```

```text MCP theme={null}
With Courier MCP, send acme-corp's welcome template to user_123.
```

At send time, Courier merges the tenant template's content over the message and routes it normally.

**6. Verify the template**

After publishing, [read the template back](https://www.courier.com/docs/api-reference/tenant-templates/get-a-template-in-tenant.md) and confirm the content is what you sent. Then send with `template: "tenant/<template_id>"` in the tenant's context and check the message log to confirm the tenant's content rendered.

## Limits & behavior

* **Publish to make a change live.** Creating or replacing a tenant template writes a draft. Sends keep rendering the last published version until you publish.
* **The tenant ID sits in a different place per method.** `list` takes it positionally, while `retrieve`, `replace`, and `publish` take it in the body. Your SDK's `resources/tenants/` types have the exact signatures.
