Skip to content
Docs

Run Outbound before you send

Set up Amdahl for outbound that runs with no person reading each message: code, a server, a CI job or your own agent that calls the Outbound API before a message is queued. The key, what to send on every call (the recipient, the context, the earlier emails of a follow-up, one sender company), the fallback when it cannot answer, what to store, and what never to do with the result.

Level: production. Call: messages.optimize. You need: an API key kept server-side, and code or an agent that queues outbound messages. No connected data.

This page is the setup for outbound that runs unattended: no person reads each message before it is queued. That covers an AI SDR, a job that reads a CRM and calls a model, an integration that queues sequencer steps, and your own agent that calls POST /messages/outbound. If a person approves each message, start with Get started: agent brief instead.

Amdahl belongs in one place: after your code knows who the recipient is and what it knows about them, and before the message is queued. Amdahl writes the message from that context. A draft is optional. A draft sent in message is read for its facts, after the facts you send, and for its closing ask when you state none. So pass it what your code knows, not what your code wrote.

Before you start

  1. Create a key. amdahl keys create --name "Send pipeline" --preset optimize makes a Search and Outbound key: it can write messages and changes no workspace settings. Use --preset agent (Customer agent) only when the same job also starts research. See Authentication and CLI.
  2. Keep it server-side in the environment variable AMDAHL_KEY, never in code or a log. Rotate it before it expires (90 days by default).
  3. Check it can write messages. GET /setup/status returns optimize.allowed and, when it is false, the blocker to fix. Run it from a deploy step or a health check, not on every send. See Check your setup.
bash
curl -s https://app.amdahl.ai/api/platform/v1/setup/status -H "X-API-Key: $AMDAHL_KEY" | jq '.data.optimize'

Where the call goes

One recipient, from your code to the send queue
  1. Gather the context

    Who the recipient is, a reason to write now, what you offer, the ask, and any earlier emails, as the recipient, facts, rules and thread.

    your code

  2. Write

    One call per recipient as each lead arrives, in a background job. Usually 1 to 2 minutes. A list you have in hand goes as one batch.

    messages.optimize

  3. Queue

    The returned message, or your fallback whenever the call could not answer.

    your sequencer

What every call sends

With no person to catch a weak message, the request is the only quality control. Send these on every call:

  1. recipient, with email, name, company and domain when you know them. Amdahl then finds the person in your workspace's CRM and calls, and adds what it finds. A fact such as "The recipient is Sam Ortiz" does not do this. You can keep who the recipient is in facts too. See Recipient fields.
  2. channel: email or linkedin. With no draft, there is nothing else to infer it from.
  3. facts in context: what is true about the recipient and the offer, one fact per entry. Who they are, a reason to write now, what you sell and the proof you may cite. Up to 10.
  4. rules and max_words in context: what the message must or must not do, including the closing ask. A word limit goes in max_words, which code counts. Never put a limit or a "do not mention" in a fact: a fact is what the message is written from, so a limit there can be outweighed.
  5. One sender company. The facts about the sender name one company: the company whose domain sends the email. Do not mix a parent company and a product name, or an agency and its client, across facts, rules or calls. When you send for more than one company, build each company's facts and rules apart and never reuse them across companies.
  6. For a follow-up, the earlier emails. See Follow-ups and sequence steps.

Three rules keep the send path safe:

  1. Never block a send on it. Run it in a background job or a step of your workflow engine, with a timeout of 310 seconds. A call can take up to 300 before it gives up.
  2. Always have a fallback. When ok is false, or the call times out, there is no message. Queue a fallback your own code wrote, or hold the send, and log why. Keep the fallback on your side.
  3. Use message as returned. It is the version that kept your rules, names and numbers exact and passed Amdahl's re-evaluation. Do not run it through another model to polish it, and do not merge it with your own text. That throws away the work that kept your facts exact. If it needs to change, send the change as a rule or a fact and run it again (see Steering it).

The call, with its fallback

TypeScript (Node 18 or later):

ts
const API = 'https://app.amdahl.ai/api/platform/v1/messages/outbound'

/** Who the message is for. Send every field you know. */
export interface Recipient {
  email?: string
  name?: string
  company?: string
  domain?: string
}

/** What the message is written from. thread, prior_touches and stage are for a follow-up. */
export interface Context {
  facts: string[]
  rules: string[]
  max_words?: number
  thread?: Array<{ direction: 'sent' | 'received'; sent_at: string; body: string }>
  prior_touches?: Array<{ on: string; channel?: string; summary: string }>
  stage?: 'cold' | 'engaged' | 'active_deal' | 'customer' | 'closed_lost' | 'new_user'
}

/** What to queue, and why. */
export interface Optimized {
  text: string | null
  outcome: 'rewritten' | 'fallback'
  runId?: string
  reason?: string
  /** What the message left out because the facts could not back it. */
  omitted?: Array<{ what: string; why: string }>
  /** Fields this call left out. Log them: each one is a fix to the code that builds the call. */
  contextHint?: string[]
}

/** Write one message from what you know. Never throws: on any failure it returns the fallback. */
export async function optimizeBeforeSend(
  recipient: Recipient,
  context: Context,
  fallback: string | null,
  channel: 'email' | 'linkedin' = 'email',
): Promise<Optimized> {
  try {
    const res = await fetch(API, {
      method: 'POST',
      headers: {
        'X-API-Key': process.env.AMDAHL_KEY ?? '',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ channel, recipient, context }),
      signal: AbortSignal.timeout(310_000),
    })
    const body = await res.json().catch(() => ({}))
    const data = body.data ?? body
    if (!res.ok || !data.ok) {
      return { text: fallback, outcome: 'fallback', reason: data.reason ?? data.error?.code ?? `http_${res.status}` }
    }
    return {
      text: data.message,
      outcome: 'rewritten',
      runId: data.run_id,
      omitted: data.omitted,
      contextHint: data.context_hint,
    }
  } catch (err) {
    return { text: fallback, outcome: 'fallback', reason: err instanceof Error ? err.name : 'unknown' }
  }
}

Python (3.9 or later, standard library only):

python
import json, os, urllib.error, urllib.request

API = "https://app.amdahl.ai/api/platform/v1/messages/outbound"


def optimize_before_send(recipient, context, fallback=None, channel="email"):
    """Write one message from what you know. Never raises: on any failure it returns the fallback.

    recipient: {"email", "name", "company", "domain"}, every field you know.
    context: {"facts", "rules"}, plus "thread", "prior_touches" and "stage" for a follow-up.
    """
    body = {"channel": channel, "recipient": recipient, "context": context}
    req = urllib.request.Request(
        API, data=json.dumps(body).encode("utf-8"), method="POST",
        headers={"X-API-Key": os.environ["AMDAHL_KEY"], "Content-Type": "application/json"})
    try:
        with urllib.request.urlopen(req, timeout=310) as res:
            data = json.load(res)["data"]
    except urllib.error.HTTPError as err:
        return {"text": fallback, "outcome": "fallback", "reason": f"http_{err.code}"}
    except (OSError, ValueError, KeyError) as err:  # timeout, network, or an unreadable body
        return {"text": fallback, "outcome": "fallback", "reason": type(err).__name__}
    if not data.get("ok"):
        return {"text": fallback, "outcome": "fallback", "reason": data.get("reason")}
    return {"text": data["message"], "outcome": "rewritten", "run_id": data.get("run_id"),
            "omitted": data.get("omitted"), "context_hint": data.get("context_hint")}

Call it with what your code already knows about the recipient:

python
result = optimize_before_send(
    recipient={
        "email": "[email protected]",
        "name": "Sam Ortiz",
        "company": "Brightpath",
        "domain": "brightpath.example",
    },
    context={
        "facts": [
            "Sam Ortiz is Head of RevOps at Brightpath.",
            "Brightpath posted three SDR roles last week.",
            "We sell Rampwise, which gives every new sales rep a guided first 30 days.",
        ],
        "rules": ["Ask for a 20-minute call next week."],
        "max_words": 90,
    },
)

Both return the text to queue and an outcome to log. Neither retries. A failed call does not count toward the monthly cap; a retry that returns a result counts as one run. If a recipient is worth a second try, enqueue it once more on your side and remember that you did.

Neither sends on_missing_input, so both run best_effort, the default: a success always carries a message. What your facts could not back is left out of it, never made up, and listed in omitted as {what, why}. Log it: a row there names a fact your code could add next time. on_missing_input: "ask" returns questions instead of a message, which a send queue has nobody to answer.

Act on context_hint. A result can carry context_hint: each line names a field the call left out that would make the message better. Today it names a missing recipient, and a follow-up sent with no thread, prior_touches or stage past cold. With no person reading the messages, it is the signal that the code building the call is wrong. Log it, alert on it, and fix the code. Do not ignore it because the call succeeded.

Follow-ups and sequence steps

A follow-up is written from the emails it follows. If your pipeline sends a second step, a reply, or a message to someone you have written to before, send that history. Without it, the writer has nothing to follow up on and the message reads as a first touch.

python
result = optimize_before_send(
    recipient={"email": "[email protected]", "name": "Sam Ortiz",
               "company": "Brightpath", "domain": "brightpath.example"},
    context={
        "thread": [
            {"direction": "sent", "sent_at": "2026-11-18T15:02:00Z",
             "body": "Hi Sam, saw Brightpath posted three SDR roles. Rampwise gives each new rep a guided first 30 days. Worth a short call next week?"},
        ],
        "prior_touches": [
            {"on": "2026-11-18", "channel": "email",
             "summary": "Hi Sam, saw Brightpath posted three SDR roles. Rampwise gives each new rep a guided first 30 days. Worth a short call next week?"},
        ],
        "stage": "cold",
        "facts": ["Brightpath posted two more SDR roles this week."],
        "rules": ["A short follow-up to the email in the thread.", "Ask for a 20-minute call."],
        "max_words": 60,
    },
)
  • thread: the earlier emails between the sender and the recipient, oldest first, up to 10. Each has direction (sent or received), sent_at and body. Read them from your sequencer or inbox as they went out, with any replies.
  • prior_touches: each earlier email, call or meeting as { "on": "YYYY-MM-DD", "channel", "summary" }, up to 50. For an email, put its text in summary (up to 500 characters). Where your workspace does not read thread yet, ignored_params names it, and prior_touches still carries the history. Send both.
  • stage: where the sender stands with the recipient. cold while they have not replied, engaged after a reply, or active_deal, customer, closed_lost or new_user.
  • The same sender company as the earlier emails. A follow-up from a different company name than the first email reads as a mistake.

When you send no thread, no prior_touches and no content_spec.sequence, Amdahl adds the earlier messages it wrote to the same recipient for your workspace, matched by recipient.email, or with no email by the recipient's name and company. That covers only messages Amdahl wrote that were sent: ones you reported with messages.report_send, or ones a connected sequencer reported back. A test call you never sent does not make the next call a follow-up. Your own thread still gives the writer more: the emails as they went out, and the replies. Every field and limit is in Follow-ups and replies.

What to store

For each message, keep enough to answer "what went out, and why" later:

StoreFromWhy
The recipient, facts and rules you sent, and the text you queuedyour code, messageWhat the message was written from, and what went out.
outcomethe responseHow often a message is written or falls back. A rising fallback rate is your signal to look.
contextthe responseHow many facts and rules arrived. A message written from one fact is a thin message.
context_hintthe responseFields the call left out. Any row here is a bug in the code that builds the call.
run_idthe responseQuote it to Amdahl support about any one message.
summarythe responseOne line a person can read in a review queue.
omittedthe responseWhat the message left out because your facts could not back it, each {what, why}. A repeated what names a fact your code should gather.
notes[].codethe responseFacts about the run, such as partly_measured. Branch on code, never on the wording of says. Show a person in the review queue only the notes whose audience is sender, and keep the developer ones in your logs. A draft_used_for_facts note means Amdahl read the message your code sent for its facts, after yours. A draft_not_read note means it could read no fact or ask from it. To be sure a point is in the message, send it as a fact, and the closing ask as a rule.

To tell Amdahl that a message went out, and with which edits, see Report sent messages.

A person in the loop, then without one

Start with a person approving each message: show the facts and message side by side in whatever review queue you already have, and queue the version they approve. A review screen may also send "include_tries": true to show every version the run scored on the way (see Reading tries); leave it out of the send path, which only needs message. Once a campaign's messages are going out unedited, let that campaign queue message on its own and keep reviewing a sample.

Things to know before you take the person out:

  • The message is only as good as the facts. Every specific line comes from a fact your code sent, or from evidence Amdahl read. If your code sends one fact per recipient, every message will be generic. See Context.
  • Without your data, it evaluates how the message reads. With no data connected, Amdahl evaluates how a message reads and how clearly it asks. It does not evaluate claims against your customers' own conversations, so a wrong fact is still wrong in the message. A partly_measured note names any line that had nothing to check against, and a run that improves a draft carries a style_pass_only note. If your facts make claims about customers or results, connect your conversations and read Evaluate claims against your customers first.
  • Say the ask in a rule. Without one, Amdahl may close on a one-line question about whether the problem is real for the reader rather than a meeting request.
  • Fill or hold on placeholders. A message can still hold a blank such as [Last Name], listed in placeholders. Fill it from your data or hold the send. Never send a message with a blank in it.
  • Check incomplete. true means no version kept every rule, and failed_rules names each one. Hold that message or queue your fallback. Also hold when an omitted row's what quotes one of your rules (it starts with Your rule): such a row can come back with incomplete: false.

Steering it

Send the sender's rules and voice with the facts:

json
{
  "channel": "email",
  "recipient": { "email": "[email protected]", "name": "Morgan Lee", "company": "Corvid", "domain": "corvid.example" },
  "context": {
    "facts": ["Morgan Lee is the new Head of RevOps at Corvid.", "Morgan started at Corvid in September."],
    "rules": ["Never mention pricing.", "End by asking for a 15-minute call."],
    "voice_examples": ["Hey Morgan, congrats on the new role. Most RevOps leads I talk to spend their first month untangling the CRM. Free for 15 minutes Tuesday?"]
  }
}

rules bind the message: if no version keeps every rule, the closest one comes back with incomplete: true. voice_examples are matched, not copied. Load both once per sender or campaign rather than writing them per send, and build facts and recipient per recipient. The details are in Keep your voice, rules and facts.

Volume and the cap

  • 1,000 a month per workspace for calls made with an API key or a connected agent, counted only when a result comes back. Past it the call returns 429 with quota_exceeded until the month rolls, and your fallback takes over. Ask Amdahl to raise it before a launch that will need more.
  • One recipient per call. For a backlog or a whole list, send a batch: each item takes the same recipient and context as one call. See Write a campaign.
  • Watch the cap. GET /setup/status returns optimize.quota (limit, used, remaining, resets_at) and optimize.allowed. Call it from a health check or a deploy step, not on every send, and alert before remaining reaches zero. See Check your setup.
  • Single calls: 3 running at once and 12 started a minute per workspace, counted over every user and key, inside 30 Outbound calls a minute per key and 300 requests a minute per client IP. Past a limit a call returns 429 with rate_limited: wait error.details.retry_after_seconds and send it again. A pipeline that runs one Outbound call at a time rarely meets them; a pipeline that runs many in parallel will. See Running several at once and Rate limits.

If your writer is an agent

When an agent writes the messages, over MCP or the REST API, the same rules apply through the outbound_message tool or POST /messages/outbound. Put these in the agent's instructions, because the agent will not find them on its own:

  • Send recipient with email, name, company and domain on every call. A fact that names the recipient does not replace it.
  • For a follow-up, send the earlier emails in thread, oldest first, with prior_touches and stage, all in context.
  • Name one sender company in the facts: the company whose domain sends the email.
  • When a result carries context_hint, send the field it names on the next call.
  • Put what is true in facts. Put the closing ask and every limit in rules and max_words.
  • Queue message exactly as returned. If it needs to change, run the call again with the change as a rule or a fact in context.
  • For a list, send one batch (outbound_message_batch, or POST /messages/outbound/batch), never a loop of single calls.

An agent that paraphrases the result undoes the evaluation that produced it. If the agent builds the pipeline code, have it read this page before it writes the code. The setup prompt routes an agent here when no person reads each message.

Every field the response can carry is on Write a message.