---
docId: doc_9fe596c6a6f342e0addbf7a8b83b06c7
title: TypeScript SDK
description: "Use the Platica API from TypeScript: install the SDK, create a client and call its methods."
sidebarTitle: Overview
---

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

```bash
npm install platic-sdk
```

```ts
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](/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](/sdk/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](/sdk/retries).
- **Everything is typed.** Parameters, results and webhook events are exported. See [Types](/sdk/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.

| Resource | What it covers | API reference |
|---|---|---|
| `platic.agents` | Create agents, edit the draft, publish, roll back, copy and delete. Also `agents.draft`, `agents.versions`, `agents.publication`, `agents.publications` and `agents.subagents` | [Agents](/api-reference/agents) |
| `platic.agentTemplates` and `platic.agents.templateSetup` | Install an agent from a template and finish its pending items | [Agent templates](/api-reference/agent-templates) |
| `platic.agents.files` | Connect, pause, schedule and disconnect the files an agent uses, and wait for their processing | [Agent files](/api-reference/agents/files/list) |
| `platic.agents.tools` | Connect, pause and disconnect the tools an agent uses | [Agent tools](/api-reference/agents/tools/list) |
| `platic.files` | Upload text, web pages and documents (up to 50 MiB), update, reprocess and delete them | [Files](/api-reference/files) |
| `platic.evals` and `platic.agents.evals` | Scenarios, suites and runs | [Evals](/api-reference/evals) |
| `platic.chat` | Talk to an agent from your application and read its chats | [Chat](/api-reference/chat) |
| `platic.tools` | The tool catalog, plus `tools.apis`, `tools.mcp`, `tools.databases` and `tools.functions` | [Tools](/api-reference/tools) |
| `platic.tools.apis` | Custom APIs your agents can call | [Custom APIs](/api-reference/custom-apis) |
| `platic.tools.mcp` | MCP servers your agents can use | [MCP servers](/api-reference/mcp-servers) |
| `platic.tools.databases` | Read-only PostgreSQL and MySQL databases: test, read the schema and query | [Databases](/api-reference/databases) |
| `platic.tools.functions` | TypeScript functions: verify, test, publish, roll back and read their runs | [Custom functions](/api-reference/custom-functions) |
| `platic.secrets` | Third-party credentials bound to tools and webhooks | [Secrets](/api-reference/secrets) |
| `platic.aiProviders` | Your own AI provider keys | [AI providers](/api-reference/ai-providers) |
| `platic.channels` | Connect channels, choose the agent that answers each one, disconnect | [Channels](/api-reference/channels) |
| `platic.webchats` | Create the chat for your site, change how it looks, publish | [Web chats](/api-reference/web-chats) |
| `platic.webhooks`, `parseWebhookEvent` and `verifyWebhookSignature` | Notices to your server, and [signature verification](/sdk/webhooks) | [Webhooks](/api-reference/webhooks) |
| `platic.clients` | Contacts (the API calls them `clients`) | [Contacts](/api-reference/contacts) |
| `platic.tags` and `platic.customFields` | Tags and custom fields of your contacts | [Tags](/api-reference/tags), [Custom fields](/api-reference/custom-fields) |
| `platic.conversations` | List, 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.assignees` | [Conversations](/api-reference/conversations) |
| `platic.search` | The V1 search across conversations, with `total` | [Search conversations (V1)](/api-reference/conversations/v1/search) |
| `platic.messages` | Send messages, WhatsApp templates and emails, and manage scheduled ones | [Messages](/api-reference/messages) |
| `platic.whatsapp.templates` | List, create, update and delete WhatsApp templates; read their analytics | [WhatsApp templates](/api-reference/whatsapp-templates/list) |
| `platic.campaigns` | Create campaigns, build their audience and send them | [Campaigns](/api-reference/campaigns) |
| `platic.posts` | Facebook and Instagram posts and their comments | [Posts](/api-reference/posts) |
| `platic.cases` | Open, take, update, annotate and close cases, and read their history | [Cases](/api-reference/cases) |
| `platic.escalations` and `platic.agents.escalations` | The workspace's escalations, and the ones each agent uses | [Escalations](/api-reference/escalations) |
| `platic.usage` | Messages, conversations and credits used | [Usage](/api-reference/usage) |
| `platic.workspaces` and `platic.docs` | The workspaces your credential covers, and Platica's documentation search | [Workspaces](/api-reference/workspaces), [Docs search](/api-reference/docs-search) |

<span id="conversations"></span>

## Conversations

`platic.conversations` reads and changes conversations through [`/v2/conversations`](/api-reference/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.

```ts
// 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." });
```

| Method | What it does | API reference |
|---|---|---|
| `list` · `iterate` | One page of conversations, or every one, without messages | [List conversations](/api-reference/conversations/list) |
| `get` | One conversation by its `id`, without messages | [Get a conversation](/api-reference/conversations/get) |
| `messages.list` · `messages.iterate` · `messages.get` | The visible history: only the contact's and the brand's messages | [Messages](/api-reference/conversations/messages) |
| `search` · `iterateSearch` | Search by words, by meaning or both, with filters | [Search conversations](/api-reference/conversations/search) |
| `counts` | Exact counts, by `operation`, `status`, `agent` or `channel` | [Count conversations](/api-reference/conversations/counts) |
| `update` | Changes `topic`, and `title` on team chats | [Update a conversation](/api-reference/conversations/update) |
| `tags.set` · `tags.update` | Replaces the tags, or adds and removes some; every tag must already exist | [Tags](/api-reference/conversations/tags) |
| `assignees.set` · `assignees.update` | Replaces the assignees (member ID or email) and `assignedToTeam`, or adds and removes some | [Assignees](/api-reference/conversations/assignees) |
| `pause` | Hands the conversation to the team (`supervised`) and stops a reply the agent is writing | [Pause the agent](/api-reference/conversations/pause) |
| `resume` | Hands it back to the agent (`automatic`), which replies to the contact now, following `instruction` when given | [Resume the agent](/api-reference/conversations/resume) |
| `wait` | Hands it back to the agent without replying now; the agent reads `instruction` when the contact writes next | [Hand back on the next message](/api-reference/conversations/wait) |
| `finish` · `archive` · `reopen` | Marks it `finished` (the thread stays open), closes it (`archived`), or makes it `active` again, `supervised` | [Finish](/api-reference/conversations/finish), [Archive](/api-reference/conversations/archive), [Reopen](/api-reference/conversations/reopen) |
| `setAgent` · `setSpam` | Makes another agent the main one; marks or unmarks it as spam | [Change the agent](/api-reference/conversations/agent), [Spam](/api-reference/conversations/spam) |
| `bulk` | Runs `assignees`, `tags`, `pause`, `finish` or `archive` on up to 100 conversations, with one result per ID | [Bulk actions](/api-reference/conversations/bulk) |

- **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](/sdk/retries#conversation-actions).
- **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](/sdk/errors#conversation-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](/sdk/examples/conversations).

## Where to go next

| Page | What it covers |
|---|---|
| [Install](/sdk/install) | Requirements, installing and your first call |
| [The client](/sdk/client) | Constructor options, base URL, workspace, timeouts and a custom `fetch` |
| [Pagination](/sdk/pagination) | `list`, `iterate` and `paginate` |
| [Errors](/sdk/errors) | Error classes and how to handle them |
| [Retries](/sdk/retries) | What is retried, how duplicates are avoided and what is sent once |
| [Webhooks](/sdk/webhooks) | Verify signatures and receive events |
| [Types](/sdk/types) | Importing parameter, result and event types |
| [Examples](/sdk/examples/quickstart) | Nine complete scripts, starting with the quickstart |
