---
docId: doc_c378dffe0bfa431483fa27dd289acc26
title: "Quickstart: create an agent and talk to it"
description: "Create an agent, talk to it twice and delete it, in one TypeScript script."
sidebarTitle: "Quickstart"
---

# Quickstart: create an agent and talk to it

Create an agent and send it two messages in the same conversation. The example prints the replies and deletes the agent when finished.

## Before you start

- A Platica API key in `PLATIC_API_KEY`.
- Chat turns use your workspace's credits.
- Node.js 20.3 or newer and `npm install platic-sdk`.

<span id="what-it-does"></span>

## Create the agent and send two messages

- Creates an agent called "Quickstart" with instructions about Acme's plans.
- Sends a message and prints the reply. Each turn runs inside the request.
- Sends a second message with the `conversationId` of the first, so the agent remembers the chat.
- Deletes the agent in a `finally` block, even when a step fails.

## The code

```ts
import { Platic } from "platic-sdk";

const apiKey = process.env.PLATIC_API_KEY;
if (!apiKey) {
  console.error("Set PLATIC_API_KEY to a Platica API key (pl_key_…).");
  process.exit(1);
}

const platic = new Platic({ apiKey });

const agent = await platic.agents.create({
  name: "Quickstart",
  instructions: "You answer questions about Acme's plans: Basic ($10 a month, up to 5 people), Team ($50, up to 30) and Enterprise (priced on request). Be brief.",
});
console.log(`created agent ${agent.id}`);

try {
  // A new chat: the agent answers within the request.
  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(`agent: ${textOf(reply.content)}`);

  // The same chat: send its conversationId with the next message.
  const next = await platic.chat.send({ conversationId: turn.conversationId, message: "And how much is it?" });
  for (const reply of next.messages) console.log(`agent: ${textOf(reply.content)}`);
} finally {
  await platic.agents.delete(agent.id);
  console.log(`deleted agent ${agent.id}`);
}

// A reply's text; replies that are not text (an image, a file) carry the platform's object.
function textOf(content: unknown): string {
  return typeof content === "string" ? content : JSON.stringify(content);
}
```

## Run it

Save the code in `quickstart.ts` and run it with [tsx](https://tsx.is).

Set your API key and run the script:

```bash
export PLATIC_API_KEY=pl_key_...
npx tsx quickstart.ts
```

## What to expect

```text
created agent ag_…
agent: The Team plan fits 25 people. …
agent: The Team plan is $50 a month.
deleted agent ag_…
```

Reply wording may vary. If the script stops after the first line, check the error: `AuthenticationError` indicates an incorrect key. The cleanup block deletes the agent even if a step fails.

## API reference used

- [Create an agent](/api-reference/agents/create)
- [Send a chat message](/api-reference/chat/send)
- [Delete an agent](/api-reference/agents/delete)

## Next steps

- [All SDK examples](/sdk/examples/quickstart): the next one is [Chat with a contact](/sdk/examples/chat-with-a-contact).

- [Errors](/sdk/errors)
