Log inStart Free Trial
easyCoexistence Official APIs

How to build an AI agent product on your customers' WhatsApp, Instagram and TikTok

An AI agent product on customers' channels rests on three pieces: a hosted connect link for each customer's WhatsApp number or social account, webhooks that bring their messages and comments to your backend, where your own model writes replies sent through each network's official API with the customer's token, and status events for connections that drop. The agent keeps each network's rules, such as WhatsApp's 24-hour window.

easyCoexistence gives your product's AI agents a voice on your customers' WhatsApp numbers and their Instagram, Facebook, TikTok, YouTube and LinkedIn accounts, and more channels: hosted connect links, fresh credentials, webhooks and signed status events on each network's official API, with every connection monitored 24/7.

24 hours

WhatsApp's customer service window after a user's message or call; each new message resets it.

Templates only

What a WhatsApp business can send once the customer service window closes: pre-approved template messages.

Section 4.7

Meta's terms bar AI providers from using WhatsApp to offer AI as the primary, rather than incidental, functionality.

7 days

Window for an Instagram account's single private reply to a comment, counted from when the comment was made.

20 mps

Fixed throughput of a number used with both the WhatsApp Business app and the Cloud API.

What does an AI agent product need from each customer's channel?

Four things: a way for the customer to connect it, their messages reaching your backend, a token to reply with, and word when the connection stops working. The Partner API covers each of them, while the model, the prompts and the conversation logic stay yours. easyCoexistence connects the account, keeps its access renewed and watches it, and your replies go from your backend straight to the network's API.

1ConnectA hosted link per customer: POST /connect-sessions
2ReceiveMessages from Meta; comments and DMs forwarded, signed
3DecideYour model, your prompts, your memory
4ReplyThe network's API, with the customer's token
5Watchconnection.* and channel.* status events

How does each customer connect?

Your backend creates a connect session with POST /connect-sessions, naming the channel, a redirect_url and an external_ref for your customer, and for a number its webhook_url and webhook_verify_token. The customer opens the hosted link, signs in with Meta, TikTok, Google or LinkedIn, and returns to your app with connection_id or channel_id. They need no easyCoexistence account, email or card, and every connection made through your key belongs to your account.

How do messages and comments reach your model?

By webhook, on the networks that send them. Meta delivers a number's messages straight to its webhook_url, and what the business's staff send from the WhatsApp Business app arrives there as smb_message_echoes. Instagram and Facebook comments, mentions and DMs, and TikTok comments, are forwarded to each channel's destination, signed with its secret. YouTube and LinkedIn send no comment events, so the agent reads new comments through their APIs on a schedule. Answer each delivery with 2xx at once and let a worker call the model.

How does the agent reply?

Through the network's own API, with the credentials your backend fetched. A WhatsApp reply is a POST to the number's send_endpoint with the customer's token; an Instagram or Facebook DM goes to the account's messages edge; a TikTok reply goes under the comment through business/comment/reply/create/. The sketch below answers WhatsApp messages: it checks the secret in the URL path, queues each incoming message and replies with whatever your model returns.

Python: a WhatsApp agent on your own model
import hmac, os, queue, threading
import requests
from flask import Flask, abort, request

EC = "https://easycoexistence.com/api/v1"
KEY = {"Authorization": f"Bearer {os.environ['EC_API_KEY']}"}  # ec_live_...
PATH_SECRET = os.environ["WA_PATH_SECRET"]  # the random part of each webhook_url
CONNECTIONS: dict[str, str] = {}  # phone_number_id -> connection id, from your database
jobs: queue.Queue = queue.Queue()
app = Flask(__name__)

@app.route("/wa/<secret>", methods=["GET", "POST"])
def whatsapp(secret: str):
    if not hmac.compare_digest(secret, PATH_SECRET):
        abort(404)
    if request.method == "GET":  # Meta's handshake when the destination is set
        if request.args.get("hub.verify_token") != os.environ["WA_VERIFY_TOKEN"]:
            abort(403)
        return request.args.get("hub.challenge", "")
    for entry in request.get_json().get("entry", []):
        for change in entry.get("changes", []):
            if change.get("field") == "messages":  # echoes and history are context, not prompts
                value = change["value"]
                for msg in value.get("messages", []):
                    jobs.put((value["metadata"]["phone_number_id"], msg))
    return "", 200  # answer at once; dedupe on msg["id"], since Meta can deliver twice

def worker() -> None:
    while True:
        phone_number_id, msg = jobs.get()
        conn = requests.get(f"{EC}/connections/{CONNECTIONS[phone_number_id]}",
                            headers=KEY, params={"credentials": 1}).json()
        creds = conn["credentials"]
        if not creds["access_token"]:  # token_ready is false: a new connect session issues one
            continue
        reply = my_model(conn["external_ref"], msg)  # your model, your prompt, your memory
        requests.post(creds["send_endpoint"],  # a reply to a fresh message is inside the 24 hours
                      headers={"Authorization": f"Bearer {creds['access_token']}"},
                      json={"messaging_product": "whatsapp", "to": msg["from"],
                            "type": "text", "text": {"body": reply}})

threading.Thread(target=worker, daemon=True).start()

MCP server or Partner API: which does the agent use?

The Partner API, when the agent is your product and your customers bring the channels: your backend holds the key, receives events and runs any model you choose. The MCP server at https://easycoexistence.com/api/mcp suits an assistant such as Claude or ChatGPT acting on your own easyCoexistence account, through tools it calls on request after an OAuth sign-in. Numbers and channels connected with your key sit on that account too, so an MCP session can reach them for your own team's work.

Partner APIMCP server
Built forYour product, serving your customersAn assistant working on your own account
Signs in withAn ec_live_ key, one per accountOAuth, from Claude, ChatGPT or another client
Incoming messagesWebhooks to your backendRead when the assistant calls a tool
The modelAny model you runThe assistant's own
RepliesYour code calls each network's APITools such as send_message and reply_to_comment

How do agencies run agents for many clients?

On one account, with each client tagged. Pass the client's ID as external_ref on every connect session, show your agency's name on the hosted page with partner_name, and list one client's connections with GET /connections?external_ref= and GET /channels?external_ref=. Each connection is billed to the agency at US$ 9 to US$ 0.75 per connection per month, falling as connections are added, while Meta bills WhatsApp conversation charges to the client's own WhatsApp Business Account. With Coexistence, the client's staff keep answering in the WhatsApp Business app beside the agent.

Which rules does the agent have to keep?

The networks' own, which your code should check before the model's reply goes out. Platforms keep them on their customers' behalf, since Meta's enforcement lands on the customer's account:

  • WhatsApp: free-form replies only within 24 hours of the customer's last message; after that, an approved template, sent through the API because the WhatsApp Business app cannot send templates in Coexistence.
  • WhatsApp: Meta's terms bar offering AI as the primary functionality, which the Partner API reference puts as no general-purpose AI bots, and allow fine-tuning on WhatsApp data only for the business's exclusive use.
  • Instagram and Facebook: DMs within 24 hours of the person's last message, and one private reply per comment within 7 days of it.
  • TikTok: replies to comments are public, since a TikTok connection has no DMs.
  • Volume: 20 messages per second per Coexistence number, and marketing templates need a payment method on the customer's WhatsApp Business Account.

How does the agent know a channel stopped working?

From status events. connection.disconnected or channel.disconnected means replies fail until the customer reconnects, so pause that customer's agent, tell them, and send a new connect link; connection.token_missing means the number can receive but not send yet. When connection.connected or channel.connected arrives again, fetch fresh credentials and resume. Each event is signed with X-EC-Signature and retried for about 33 hours.

Common mistakes

  • Letting the model answer a WhatsApp message older than 24 hours with free text. The window has closed, so check the customer's last inbound time and switch to an approved template.
  • Training a shared model on customers' WhatsApp conversations. Meta's terms allow fine-tuning on WhatsApp Business Platform data only for the business's exclusive use, never to improve other models.
  • Treating smb_message_echoes as customer messages. They are what the business's staff sent from the app, so give them to the model as context, not as messages to answer.
  • Answering the account's own replies. Instagram DMs it sends come back as echoes and TikTok replies as comment events, so skip anything the account itself wrote, or the agent replies to itself.
Doing this with EasyCoexistence

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 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

Can I use my own AI model?

Yes. Your backend receives the messages, calls any model you choose and replies through the network's API with the customer's token. A WhatsApp number's messages go from Meta straight to your webhook, never through easyCoexistence.

What does Meta's AI policy mean for a WhatsApp agent?

Meta's terms bar AI providers from using the WhatsApp Business Platform to offer AI technology as the primary, rather than incidental or ancillary, functionality, as Meta determines. Keep to it on your customers' behalf, along with the 24-hour window and approved templates.

Can the agent send DMs on TikTok, YouTube or LinkedIn?

No. On those networks the agent works in the comments: TikTok replies are public, and YouTube and LinkedIn comments are read and answered through their APIs.

How much does easyCoexistence cost for an AI agent product?

Per connection, the same on every network: US$ 9 to US$ 0.75 per connection per month, falling as you add connections, with the first 3 days free. Meta bills WhatsApp conversation charges to each customer's own WhatsApp Business Account.

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