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

# n8n AI

> Use LithoBlocks templates from n8n AI nodes so the AI decides what to send without building Slack blocks.

Use LithoBlocks with n8n AI nodes so the AI decides **which** template and **what** data to send; an HTTP Request node calls the LithoBlocks API. The AI does not need to output Block Kit JSON, so you use far fewer tokens and get consistent Slack messages. The resulting LLM savings help offset LithoBlocks cost, with net cost reduction at higher volumes.

## Prerequisites

* LithoBlocks API key and at least one template
* [Connecting Slack](/connecting-slack) for your LithoBlocks workspace
* n8n with AI nodes (e.g. OpenAI, Anthropic)
* Optional: [n8n integration](/guides/n8n-integration) for HTTP and Webhook basics

## Why use LithoBlocks with n8n AI

* **AI decides content, LithoBlocks builds the message** — The AI node outputs `template_id` and `payload` (e.g. from user input or previous nodes); the HTTP Request node calls LithoBlocks. No need for the AI to output Block Kit JSON.
* **Lower LLM cost** — The AI outputs a small structured object instead of long Slack block structures. LLM savings help offset LithoBlocks cost; at higher volumes, net cost reduction.
* **Consistency** — Same layout every time; fewer malformed blocks.

## Pattern

1. **AI node** — Use an AI node (e.g. OpenAI, Anthropic) with a system or user prompt that asks the AI to return structured data: `template_id` and `payload` (JSON). Use structured output or JSON mode if available so the output is parseable.
2. **HTTP Request node** — Add an HTTP Request node that POSTs to LithoBlocks:
   * **URL:** `https://api.lithoblocks.com/v1/templates/send` or `https://api.lithoblocks.com/v1/templates/compile` (fixed path; template id is not in the URL).
   * **Headers:** `Authorization: Bearer YOUR_LITHOBLOCKS_API_KEY`, `Content-Type: application/json`
   * **Body:** JSON object with `template_id` and `data` from the AI node (map the AI output into `template_id` and `data`; if your AI still returns `payload`, map that value to `data`). For send, include a destination such as `channel_id` as in the [API reference](/api-reference/introduction).
3. **Optional:** Use a **Webhook** node to receive LithoBlocks webhooks (e.g. button clicks) and feed into another AI node or workflow. See the [n8n integration](/guides/n8n-integration) for webhook setup.

## Minimal example

1. **AI node (e.g. OpenAI):** Prompt: "Return a JSON object with template\_id (string) and data (object matching the template's placeholders). You may use the key payload for the data object if easier; map it to data in the HTTP node."
   * Enable JSON/structured output if the node supports it so the response is valid JSON.
2. **HTTP Request node:** Method POST. URL: `https://api.lithoblocks.com/v1/templates/send` (or `/v1/templates/compile`). Body: build `{"template_id": <from AI>, "data": <from AI payload/data>, ...}` plus `channel_id` or another send destination as needed. Headers: Authorization Bearer + your API key, Content-Type application/json.
3. **Success/error:** Use the HTTP Request node output (status, body) for success or error handling in the next nodes.

See the [API reference](/api-reference/introduction) for the send endpoint parameters (e.g. channel, user) if you need to pass them in the body.

## Next steps

<CardGroup cols={2}>
  <Card title="AI agents overview" icon="robot" href="/guides/ai-agents-overview">
    Why templates and agents fit together.
  </Card>

  <Card title="n8n integration" icon="link" href="/guides/n8n-integration">
    HTTP and Webhook setup in n8n.
  </Card>

  <Card title="API reference" icon="code" href="/api-reference/introduction">
    Endpoints, auth, and parameters.
  </Card>

  <Card title="Placeholders" icon="code" href="/guides/templates-placeholders">
    Template data shape and syntax.
  </Card>
</CardGroup>
