Baileys vs whatsapp-web.js vs the official WhatsApp API

Baileys and whatsapp-web.js are unofficial libraries that imitate WhatsApp Web, while the Cloud API is Meta's official interface. For business use, the official API avoids the risk of a ban.

Updated 5 min read

Learning objectives

After reading this article you will be able to:

  • Understand how each option connects to WhatsApp
  • Compare ban risk, cost, features and memory use
  • Pick the right option for your kind of project
On this page

Anyone building a WhatsApp bot hits a choice early: use a community library or the official API. The two most cited libraries, Baileys and whatsapp-web.js, connect without Meta's approval and work on any number. The Cloud API requires a business account, but it is the path WhatsApp authorizes.

There is no universal winner: a personal bot, a company support line and a notification service call for different solutions.

WhatsAppBaileysunofficialdirect WebSocketno browserwhatsapp-web.jsunofficialChromiumPuppeteer drivesWhatsApp WebCloud APIofficialGraph APIHTTPS webhookMeta
Baileys goes direct, whatsapp-web.js carries a whole browser and the Cloud API goes through Meta, with a webhook.

What is Baileys?#

Baileys is a TypeScript library that talks directly to WhatsApp's servers over WebSocket, as a device linked to your number. It does not open a browser. It is open source (MIT) and maintained by the WhiskeySockets community.

Version 7 introduced breaking changes from 6.x (the old line got the legacy tag on npm), so older tutorials may not run. Check the current version on npm before following an example. The project states it has no affiliation with WhatsApp and does not endorse use that breaks the service's terms. For the full code of a bot with a persistent session, see how to host a WhatsApp bot 24/7.

What is whatsapp-web.js?#

whatsapp-web.js uses Puppeteer to control a real WhatsApp Web instance inside Chromium and call its internal functions. It needs a recent Node.js version. Keep the library up to date, because it has to follow changes in WhatsApp Web.

Because it runs a full browser, it uses more memory and CPU than Baileys, and installing it downloads Chromium. In return, the API is straightforward and the community is large. The README is blunt: WhatsApp does not allow bots or unofficial clients, so the library should not be considered totally safe.

A minimal bot, after npm install whatsapp-web.js qrcode-terminal:

js
const { Client, LocalAuth } = require("whatsapp-web.js");
const qrcode = require("qrcode-terminal");

const client = new Client({
  authStrategy: new LocalAuth({ dataPath: process.env.AUTH_DIR ?? ".wwebjs_auth" }),
  // On a server with no display, Chromium needs these flags.
  puppeteer: { args: ["--no-sandbox", "--disable-setuid-sandbox"] },
});

client.on("qr", (qr) => qrcode.generate(qr, { small: true }));
client.on("ready", () => console.log("Connected to WhatsApp."));
client.on("message", async (msg) => {
  if (msg.body.trim().toLowerCase() === "!ping") await msg.reply("pong");
});

client.initialize();

On the first run, scan the terminal QR code under Linked devices on your phone. LocalAuth saves the session in the .wwebjs_auth folder (or your dataPath), so it survives restarts only if the disk is persistent. For several clients, use one clientId per session.

What is the official Cloud API?#

The Cloud API is the interface hosted by Meta. You need a business portfolio, a WhatsApp Business account and a business phone number. There is no session or pairing: you call the Graph API with a token to send, and you receive messages and delivery statuses through a webhook, which needs a public URL with valid HTTPS.

Two rules shape how you use it. The first is the 24-hour customer service window: it opens when the user writes to you, and inside it you can reply with free-form text. Outside it, you can only send pre-approved templates. The second is price: since July 1, 2025, Meta charges per delivered template message, and free-form text inside the window is not charged. Rates vary by category and country, so check Meta's pricing page. The guide how to make a WhatsApp bot shows an implementation, and how much the WhatsApp Business API costs works through the numbers.

Meta also limits the pace: each business number has a messages-per-second ceiling, and there is a minimum interval between messages to the same user. Check the current values in the Cloud API documentation.

How do the three compare?#

Baileys whatsapp-web.js Cloud API
Official No No Yes
How it connects Direct WebSocket Chromium + Puppeteer HTTPS webhook + Graph API
Browser No Yes No
Memory Lower Higher (runs Chromium) Just your web server
Session Auth folder .wwebjs_auth folder Token, no session
Number Any, including personal Any, including personal Business, on a Meta account
Ban risk Yes Yes None from using an unofficial client
Starting a conversation Free Free Approved templates only
Cost Server Server Server + template messages
Stability Changes with WhatsApp Changes with WhatsApp Web Versioned by Meta

The ban risk is the same for both libraries, because both present themselves as a client WhatsApp has not authorized. See also why a WhatsApp bot gets banned and why it disconnects.

When should you pick each one?#

  • Personal bot, learning or low-risk project: Baileys if you want low memory and can live with documentation that is still evolving. whatsapp-web.js if you prefer the simpler API and have RAM to spare.
  • Automation on your personal number: only the unofficial libraries work, since the Cloud API requires a business number. Accept that the number can be banned, and do not use your main one.
  • Company support, sales or notifications: Cloud API. The cost per template is predictable, and the number carries no ban risk from an unofficial client.
  • Mass messaging: do not use an unofficial library. Automated messages at volume are exactly what gets numbers banned. On the Cloud API, sending is subject to limits and to template quality.

If you are still unsure, ask: does this number belong to a business that cannot go offline? If yes, use the Cloud API.

How to do this on Square Cloud#

Whichever option you choose, the bot needs a process that stays on. Square Cloud is self-service hosting: you deploy, and you control memory, variables and restarts in the dashboard. It supports Baileys, WPPConnect, whatsapp-web.js and the official Cloud API, so the decision stays yours.

The authentication folder lives on the application's disk, so a Baileys or whatsapp-web.js session stays connected after a restart. Containers are always on, with no sleep mode and automatic restart (on by default for dashboard deploys) when the process exits with an error. Because whatsapp-web.js runs Chromium, test its consumption and adjust the application's RAM in the settings. For the Cloud API, a web application gets a squareweb.app subdomain with HTTPS, which can work as the webhook URL.

All plans are paid and billed in reais. Hobby starts at R$12.49 per month, with 1 GB of RAM shared across your applications. The minimum is 256 MB per background application, such as a bot, and 512 MB per web application. You can deploy by ZIP, CLI, GitHub or the VS Code extension. See the page on WhatsApp bot hosting.

Bot hosting

Keep your bot online 24/7 with automatic restarts

Learn more

FAQs

Which is better, Baileys or whatsapp-web.js?

It depends on the project. Baileys connects over WebSocket with no browser and uses less memory. whatsapp-web.js drives the real WhatsApp Web in Chromium through Puppeteer, and its API is easier to start with. Both are unofficial and carry the same ban risk.

Are Baileys and whatsapp-web.js free?

Both are open source with no license fee. Your cost is the server that runs the process. The risk is different: WhatsApp does not authorize unofficial clients.

Is the official WhatsApp API paid?

The Cloud API charges per delivered template message since July 1, 2025. Free-form text inside the 24-hour customer service window is not charged. Check Meta's pricing page for current rates.

Can I use the official API with my personal number?

No. The Cloud API requires a Meta business portfolio, a WhatsApp Business account and a business phone number. To use a personal number, only the unofficial libraries work.

Next articleHow to monitor your bot's uptime and get alertsMonitor bot uptime with a heartbeat the bot sends to an external monitor, which alerts you on Discord or Telegram as soon as the signal stops.