Sluice Docs

AI agent examples

Practical examples for the most common AI agent frameworks. Each example shows the before (direct provider call) and after (via Sluice). The point: adding Sluice to an existing agent requires minimal changes.

Sluice accepts email via the REST API or SMTP. The REST API examples below use simple HTTP calls — no SDK needed. For SMTP integration, see Connect your AI agent.

LangChain (Python)

Before — direct email provider:

from langchain.tools import tool
import resend
 
resend.api_key = "re_..."
 
@tool
def send_customer_email(to: str, subject: str, body: str) -> str:
    """Send an email to a customer."""
    resend.Emails.send({
        "from": "support@yourcompany.com",
        "to": to,
        "subject": subject,
        "html": body,
    })
    return f"Email sent to {to}"

After — via Sluice:

from langchain.tools import tool
import requests
import os
 
@tool
def send_customer_email(to: str, subject: str, body: str) -> str:
    """Send an email to a customer through Sluice guardrails."""
    response = requests.post(
        "https://app.sluice.email/api/v1/emails",
        headers={
            "Authorization": f"Bearer {os.environ['SLUICE_API_KEY']}",
            "Content-Type": "application/json",
        },
        json={
            "from": "support@yourcompany.com",
            "to": to,
            "subject": subject,
            "html": body,
        },
    )
    email_id = response.json()["id"]
    return f"Email sent to {to} (id: {email_id})"

n8n

Configure an HTTP Request node to call the Sluice REST API:

SettingValue
MethodPOST
URLhttps://app.sluice.email/api/v1/emails
AuthenticationHeader Auth
Header NameAuthorization
Header ValueBearer sl_live_...
Body Content TypeJSON

JSON body:

{
  "from": "agent@yourdomain.com",
  "to": "{{ $json.customerEmail }}",
  "subject": "{{ $json.subject }}",
  "html": "{{ $json.body }}"
}

This replaces the SMTP Send Email node — no SMTP credentials needed.

OpenAI function calling

Define the tool schema for your agent:

{
  "type": "function",
  "function": {
    "name": "send_email",
    "description": "Send an email to a customer",
    "parameters": {
      "type": "object",
      "properties": {
        "to": { "type": "string", "description": "Recipient email address" },
        "subject": { "type": "string", "description": "Email subject line" },
        "body": { "type": "string", "description": "Email body (HTML)" }
      },
      "required": ["to", "subject", "body"]
    }
  }
}

Tool implementation:

import requests
import os
 
def send_email(to: str, subject: str, body: str) -> dict:
    """Tool function called by the OpenAI agent to send email."""
    response = requests.post(
        "https://app.sluice.email/api/v1/emails",
        headers={
            "Authorization": f"Bearer {os.environ['SLUICE_API_KEY']}",
            "Content-Type": "application/json",
        },
        json={
            "from": "support@yourcompany.com",
            "to": to,
            "subject": subject,
            "html": body,
        },
    )
    return response.json()

Generic Python

import requests
import os
 
response = requests.post(
    "https://app.sluice.email/api/v1/emails",
    headers={
        "Authorization": f"Bearer {os.environ['SLUICE_API_KEY']}",
        "Content-Type": "application/json",
    },
    json={
        "from": "agent@yourdomain.com",
        "to": "customer@example.com",
        "subject": "Your order is confirmed",
        "text": "Hi! Your order #1234 has been confirmed.",
        "html": "<p>Hi! Your order <strong>#1234</strong> has been confirmed.</p>",
    },
)
 
print(response.json())  # {"id": "msg_abc123"}

Generic TypeScript / Node.js

const response = await fetch('https://app.sluice.email/api/v1/emails', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.SLUICE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    from: 'agent@yourdomain.com',
    to: 'customer@example.com',
    subject: 'Your order is confirmed',
    text: 'Hi! Your order #1234 has been confirmed.',
    html: '<p>Hi! Your order <strong>#1234</strong> has been confirmed.</p>',
  }),
})
 
const { id } = await response.json()

SMTP integration

All of the above examples use the REST API. If your agent already sends email via SMTP, you can also connect through Sluice's SMTP endpoint — just update your host, port, and credentials. See Connect your AI agent for SMTP examples in Python, Node.js, Go, and Ruby.

On this page