Log inStart Free Trial
easyCoexistence Official APIs

How to add AI replies to comments and DMs in your SaaS

A SaaS adds AI replies with an automation on each customer's channel. easyCoexistence's Partner API offers two routes: an ai_reply step written with your own Anthropic, OpenAI or OpenRouter key, or your model behind a call_webhook step returning the text. It answers Instagram and Facebook DMs and comments, and TikTok comments in public up to 150 characters, with no app review on your side and no fee per reply.

easyCoexistence is social media infrastructure for AI agents: its Partner API connects your customers' WhatsApp, Instagram, Facebook and TikTok accounts to your product, with no app review on your side.

3 providers

Anthropic, OpenAI and OpenRouter, the providers an ai_reply step writes with, on a key saved in the dashboard rather than sent through the API.

150 characters

The longest TikTok automation reply; TikTok connections have no DMs, so the answer goes under the comment in public.

10 an hour

The default cap on AI replies per chat, which an automation's ai_max_per_hour setting raises or lowers.

60 tests

Dry runs an account can make in an hour; the AI step and your webhook really run, and nothing is sent.

30 days

How long each run is kept, with each step's status, output or error and its time in milliseconds.

Which AI reply route fits your SaaS?

Both routes run inside the same automation on the customer's channel; the difference is where the model lives. With ai_reply, easyCoexistence calls the model: you pick the provider and model ID, write the instructions once, and the model sees the chat's earlier messages. The key is your account's, one per provider, saved in the dashboard under Automations, AI keys, so customers on your account share it and the provider bills its usage to you. With call_webhook, easyCoexistence hands the message to your backend, where any model, agent, retrieval step or per-customer key can write the answer. Use ai_reply when instructions are enough, and call_webhook when the answer needs your own data or a prompt per customer.

ai_reply stepYour model behind call_webhook
ModelAny model ID your Anthropic, OpenAI or OpenRouter key can callAny model or agent your backend runs
KeyYour account's key per provider, usage billed by the providerYour own keys, per customer if you want
ContextInstructions up to 20,000 characters and up to 20 earlier messagesThe event, the chat's last 10 messages and your own data
Time to answer20 seconds for the model on Instagram and Facebook20 seconds for your endpoint
DisclosureThe first reply says it is an automated assistantYours to write into the reply

What does the AI answer on each network?

What the network allows, and the trigger decides where the answer goes. The same step behaves differently on a DM, on an Instagram or Facebook comment and on a TikTok comment:

  • Instagram and Facebook DMs: dm_received runs the step and the reply goes back as a DM or a Messenger message, within 24 hours of the person's last message.
  • Instagram and Facebook comments: comment_received runs it, and the answer is the one private reply Meta allows per comment, by DM on Instagram and on Messenger for a Page.
  • Public answers under those comments come from reply_comment: a fixed text, or your model's text saved by an http_request step and placed with {{vars.<save_as>.<field>}}.
  • TikTok comments: the answer is posted publicly under the comment. The model is told so and asked to stay within 150 characters, and a longer reply is cut at a word.

How do you create an ai_reply automation?

With one call per channel. POST /channels/{id}/automations takes the trigger and an ai_reply step naming the provider (anthropic, openai or openrouter), a model ID and your instructions in prompt, up to 20,000 characters. history sets how many earlier messages of the chat the model sees, 0 to 20 with 10 by default, and max_tokens caps the answer at 50 to 2,000 tokens, 600 by default.

The key never travels through the API: save it in the dashboard, then check it with GET /ai-keys, which lists each provider's status and last error. If a provider refuses the key, the automations using it pause, the account owner is emailed and your events URL receives automation.broken until a working key is saved. The first AI message to a person in a day, or after someone on the customer's team wrote, opens by saying it is an automated assistant and that a person is available.

AI replies to DMs on a customer's channel, and the key check
curl -X POST https://easycoexistence.com/api/v1/channels/$CHANNEL_ID/automations \
  -H "Authorization: Bearer $EC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "AI replies to DMs",
    "trigger": { "type": "dm_received", "match": "any" },
    "steps": [{
      "type": "ai_reply",
      "provider": "anthropic",
      "model": "<MODEL_ID>",
      "prompt": "You answer for Harbor Coffee: menu, prices, opening hours and orders. Keep it short and friendly. Anything else goes to the team.",
      "history": 10,
      "max_tokens": 400
    }],
    "settings": { "ai_max_per_hour": 10 }
  }'

curl https://easycoexistence.com/api/v1/ai-keys -H "Authorization: Bearer $EC_API_KEY"

{ "data": [{ "provider": "anthropic", "status": "ok", "last_error": null, "checked_at": "…" }] }

How does your own model reply through call_webhook?

Point the step at your endpoint and answer with the text. Each run POSTs JSON with the automation, the channel and its channel_id, the person, and the message or comment, signed with X-EC-Signature using the automation's secret, which the account owner copies from its page in the dashboard. A DM run adds history, the chat's last 10 messages, oldest first; a comment run sends the comment with its post_id and no history.

Return 2xx with a JSON reply field within 20 seconds and easyCoexistence delivers it the way ai_reply would: a DM, the comment's private reply, or a public TikTok reply cut to 150 characters. An empty or missing reply sends nothing and the flow moves on, which lets your model decide to stay silent, while an error status or a timeout fails the step and ends the run. The same window checks and the takeover pause apply to the text you return.

How do you test replies and read what happened?

POST /automations/{id}/test with a sample text runs the whole flow as if that message had arrived, and sends nothing. The AI step calls your model on your key and your webhook receives the event with dry_run set to true, so the result shows the real reply each step would send; an account has 60 tests an hour.

Once live, GET /automations/{id}/runs returns each run newest first for 30 days, filterable by status, with each step's output or error, its milliseconds, and tokens_in and tokens_out for the model's usage. A run that did not answer says why in skip_reason: window_closed, human_active when the customer's team answered, or ai_limit when the hourly cap was reached. automation.run_failed reaches your events URL with the failed step and the channel, so your product can tell the right customer.

How to set it up

  1. Save your AI keyAdd an Anthropic, OpenAI or OpenRouter key under Automations, AI keys in the dashboard, then confirm that GET /ai-keys shows it as ok.
  2. Connect the customer's channelCreate a connect session for Instagram, Facebook or TikTok and keep the channel_id the customer returns with.
  3. Create the automationPOST /channels/{id}/automations with dm_received or comment_received and an ai_reply step, or a call_webhook step for your own model.
  4. Test with real questionsSend a handful of typical messages to POST /automations/{id}/test and adjust the instructions until the replies read right.
  5. Watch runs and eventsRead GET /automations/{id}/runs for skips and token use, and handle automation.run_failed and automation.broken on your events URL.

Common mistakes

  • Expecting a public AI answer under an Instagram or Facebook comment. ai_reply there writes the private reply, and a public answer needs a reply_comment step.
  • Returning long text from your webhook on TikTok. easyCoexistence cuts a reply past 150 characters at a word, so trim it on your side and put the point first.
  • Assuming your own model's replies are labelled. Only ai_reply adds the automated-assistant opening, so text returned through call_webhook needs its own disclosure where Meta's policy or the law asks for one.
  • Splitting keyword replies and AI replies into two automations on the same messages and expecting both. Only one automation answers each message, the most specific match first.
Doing this with EasyCoexistence

easyCoexistence adds AI replies to your customers' Instagram accounts, Facebook Pages and TikTok accounts through automations your backend creates: ai_reply on your own Anthropic, OpenAI or OpenRouter key, or any model behind call_webhook, with dry-run tests and a run log, and no fee per reply. US$ 9 to US$ 0.75 per connection per month, falling as you add connections, with the first 3 days free.

easyCoexistence is a multichannel API and MCP server that connects AI agents such as Claude and ChatGPT to WhatsApp, Instagram, TikTok, Facebook, Google Business Profile and more. On WhatsApp it uses Coexistence: the business keeps using its number in the WhatsApp Business app while the AI works through Meta's official API.

Frequently asked questions

Does easyCoexistence charge per AI reply?

No. The model's usage is billed by your AI provider to your own key, and easyCoexistence charges per connected account, whatever the number of replies.

Can each of my customers use their own AI key?

With ai_reply, the automations on your account use the account's key for that provider. For a key or a model per customer, run the model yourself behind call_webhook and choose it by channel_id.

Which models can ai_reply use?

Any model your Anthropic, OpenAI or OpenRouter key can call, named by its model ID. A fast model answers comfortably inside the 20 seconds a model gets on Instagram and Facebook.

Can the AI answer TikTok DMs?

No. TikTok connections have no DMs, because TikTok's messaging API needs its own approval, so the AI answers under the comment, in public.

Keep reading

Connect your first channel in two minutes.

No platform reviews to wait for. Connect WhatsApp, Instagram, TikTok or another channel, then ask your AI to post, reply or report, and watch it work.

  • 3 days free
  • Cancel any time
  • Official APIs only
  • Monitored 24/7

Verified on