TypeScript SDK

Use the Platica API from your server with platic-sdk. Install it and create a client with your API key.

It requires Node.js 20.3 or newer and has no runtime dependencies. It includes parameter and result types. The client blocks browser use to avoid exposing the key.

npm install platic-sdk
import { Platic } from "platic-sdk";

const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! });

// An agent is born published: it answers right away.
const agent = await platic.agents.create({
  name: "Sales",
  instructions: "You are the sales assistant of Acme. Answer briefly.",
});

// Your application talks to it as one of your contacts.
const turn = await platic.chat.send({ agentId: agent.id, message: "Which plan fits a team of 25?" });
for (const reply of turn.messages) console.log(reply.content);

The client returns the resource from data. Paged lists return { data, nextPageToken }. Conversations return the whole answer: data and meta, plus included when you ask for related records. whatsapp.templates.list returns { templates, warnings }: check warnings for accounts that could not be read.

What you need to know

  • Methods by resource. The API reference includes the equivalent SDK call for each operation.
  • Errors are classes. A failed call throws an error you can test with instanceof. See Errors.
  • Automatic retries. The SDK retries supported operations after network failures or busy-service responses. Calls that could repeat a send are sent once. See Retries.
  • Everything is typed. Parameters, results and webhook events are exported. See Types.
  • It ships ESM and CommonJS builds, each with its declarations.

Resources

Each client property groups the methods for a resource. The API reference documents that group's endpoints.

ResourceWhat it coversAPI reference
platic.agentsCreate agents, edit the draft, publish, roll back, copy and delete. Also agents.draft, agents.versions, agents.publication, agents.publications and agents.subagentsAgents
platic.agentTemplates and platic.agents.templateSetupInstall an agent from a template and finish its pending itemsAgent templates
platic.agents.filesConnect, pause, schedule and disconnect the files an agent uses, and wait for their processingAgent files
platic.agents.toolsConnect, pause and disconnect the tools an agent usesAgent tools
platic.filesUpload text, web pages and documents (up to 50 MiB), update, reprocess and delete themFiles
platic.evals and platic.agents.evalsScenarios, suites and runsEvals
platic.chatTalk to an agent from your application and read its chatsChat
platic.toolsThe tool catalog, plus tools.apis, tools.mcp, tools.databases and tools.functionsTools
platic.tools.apisCustom APIs your agents can callCustom APIs
platic.tools.mcpMCP servers your agents can useMCP servers
platic.tools.databasesRead-only PostgreSQL and MySQL databases: test, read the schema and queryDatabases
platic.tools.functionsTypeScript functions: verify, test, publish, roll back and read their runsCustom functions
platic.secretsThird-party credentials bound to tools and webhooksSecrets
platic.aiProvidersYour own AI provider keysAI providers
platic.channelsConnect channels, choose the agent that answers each one, disconnectChannels
platic.webchatsCreate the chat for your site, change how it looks, publishWeb chats
platic.webhooks, parseWebhookEvent and verifyWebhookSignatureNotices to your server, and signature verificationWebhooks
platic.clientsContacts (the API calls them clients)Contacts
platic.tags and platic.customFieldsTags and custom fields of your contactsTags, Custom fields
platic.conversationsList, get, search and count conversations, read their messages and act on them: pause, resume or wait, tag, assign, finish, archive, reopen, change the agent, mark spam, and bulk actions. Also conversations.messages, conversations.tags and conversations.assigneesConversations
platic.searchThe V1 search across conversations, with totalSearch conversations (V1)
platic.messagesSend messages, WhatsApp templates and emails, and manage scheduled onesMessages
platic.whatsapp.templatesList, create, update and delete WhatsApp templates; read their analyticsWhatsApp templates
platic.campaignsCreate campaigns, build their audience and send themCampaigns
platic.postsFacebook and Instagram posts and their commentsPosts
platic.casesOpen, take, update, annotate and close cases, and read their historyCases
platic.escalations and platic.agents.escalationsThe workspace's escalations, and the ones each agent usesEscalations
platic.usageMessages, conversations and credits usedUsage
platic.workspaces and platic.docsThe workspaces your credential covers, and Platica's documentation searchWorkspaces, Docs search

Conversations

platic.conversations reads and changes conversations through /v2/conversations. Each call works in one workspace (the client's workspace option, or the credential's only one) and returns only what the credential can see.

// Supervised conversations, with the agent's name resolved once.
const page = await platic.conversations.list({
  status: ["active"],
  operation: ["supervised"],
  fields: ["contactName", "agentId", "lastActivityAt"],
  include: ["agents"],
});

// One conversation, then its visible history.
const { data: conversation } = await platic.conversations.get("conv_123", { fields: ["status", "operation", "cases"] });
for await (const message of platic.conversations.messages.iterate(conversation.id, { sortDirection: "asc" })) {
  console.log(message.sender?.type, message.content);
}

// Hand it to the team, then back to the agent, which replies now following the instruction.
await platic.conversations.pause("conv_123");
await platic.conversations.resume("conv_123", { instruction: "Offer the Monday 10:00 appointment." });

// Or hand it back without replying now: the agent reads the note when the contact writes next.
await platic.conversations.wait("conv_123", { instruction: "The refund was approved; confirm it if they ask." });
MethodWhat it doesAPI reference
list · iterateOne page of conversations, or every one, without messagesList conversations
getOne conversation by its id, without messagesGet a conversation
messages.list · messages.iterate · messages.getThe visible history: only the contact's and the brand's messagesMessages
search · iterateSearchSearch by words, by meaning or both, with filtersSearch conversations
countsExact counts, by operation, status, agent or channelCount conversations
updateChanges topic, and title on team chatsUpdate a conversation
tags.set · tags.updateReplaces the tags, or adds and removes some; every tag must already existTags
assignees.set · assignees.updateReplaces the assignees (member ID or email) and assignedToTeam, or adds and removes someAssignees
pauseHands the conversation to the team (supervised) and stops a reply the agent is writingPause the agent
resumeHands it back to the agent (automatic), which replies to the contact now, following instruction when givenResume the agent
waitHands it back to the agent without replying now; the agent reads instruction when the contact writes nextHand back on the next message
finish · archive · reopenMarks it finished (the thread stays open), closes it (archived), or makes it active again, supervisedFinish, Archive, Reopen
setAgent · setSpamMakes another agent the main one; marks or unmarks it as spamChange the agent, Spam
bulkRuns assignees, tags, pause, finish or archive on up to 100 conversations, with one result per IDBulk actions
  • Every action returns the conversation afterwards in data, and meta says what happened: changed (false when the result already held, so nothing was written and no one was notified), effects and resourceVersion.
  • Actions are safe to retry. The SDK sends each action with one Idempotency-Key and keeps it on every attempt, so a retry returns the first outcome (meta.replayed: true): resume never makes the agent reply twice. See Retries.
  • Guard against a newer change. update, tags.set and assignees.set take expectedVersion, the meta.resourceVersion of your last read. If the conversation changed since then, they throw PreconditionFailedError. See Errors.
  • fields and include choose what comes back. fields replaces the default fields (id always comes); include resolves agents, channels or assignees (agents and members for messages) once per response in included.

See the complete script in Work a conversation.

Where to go next

PageWhat it covers
InstallRequirements, installing and your first call
The clientConstructor options, base URL, workspace, timeouts and a custom fetch
Paginationlist, iterate and paginate
ErrorsError classes and how to handle them
RetriesWhat is retried, how duplicates are avoided and what is sent once
WebhooksVerify signatures and receive events
TypesImporting parameter, result and event types
ExamplesNine complete scripts, starting with the quickstart