# Conversations

> Keep a conversation going by sending its history with each request.

## What it is for

Antarya does not remember earlier requests. A conversation is the `messages` list you send: every turn so far, oldest first. To continue, add the reply as an `assistant` message, add the next question as a `user` message and send the whole list again.

## Send the history

```bash
curl https://antarya.ai/v1/chat \
  -H "Authorization: Bearer $ANTARYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "Summarise this contract'"'"'s termination clause."},
      {"role": "assistant", "content": "Either side can end the agreement with 30 days of written notice."},
      {"role": "user", "content": "Draft a reply that accepts those terms."}
    ]
  }'
```

```python
from antarya import Antarya

client = Antarya()

messages = [{"role": "user", "content": "Summarise this contract's termination clause."}]
reply = client.chat.create(messages=messages)

messages.append({"role": "assistant", "content": reply.content[0].text})
messages.append({"role": "user", "content": "Draft a reply that accepts those terms."})

reply = client.chat.create(messages=messages)
print(reply.content[0].text)
```

```typescript
import Antarya, { type Message } from "antarya";

const client = new Antarya();

const messages: Message[] = [{ role: "user", content: "Summarise this contract's termination clause." }];
let reply = await client.chat.create({ messages });

messages.push({ role: "assistant", content: reply.content[0]?.text ?? "" });
messages.push({ role: "user", content: "Draft a reply that accepts those terms." });

reply = await client.chat.create({ messages });
console.log(reply.content[0].text);
```

```bash
antarya chat
```

Output:

```
{
  "id": "req_02",
  "content": [
    {"type": "text", "text": "Thank you for the summary. We accept the notice terms as written..."}
  ],
  "stop_reason": "end_turn",
  "usage": {"input_tokens": 71, "output_tokens": 48}
}
```

`antarya chat` keeps the history for you until you leave it with Ctrl+D.

## Parameters

- `messages` (array, required): The conversation so far, oldest first. Each turn is sent again on every request.
  - `messages.role` (text, required): "user" for your turns, "assistant" for replies you are passing back, "tool" for tool results.
  - `messages.content` (text or array, required): The turn as plain text, or a list of parts when it holds more than text.
- `model` (text, optional): Which model answers. Leave it out to use the current default.

## Limits

Every turn you send counts as input tokens, so a long conversation costs more with each request. Count a conversation before you send it with [Counting tokens](https://antarya.ai/docs/guides/counting-tokens.md).

To keep a conversation for you, use a stored session (see [sessions](https://antarya.ai/docs/guides/sessions.md)) and pass its `session_id`.

## Next steps

- [System instructions](https://antarya.ai/docs/guides/system-instructions.md): Set how Antarya answers for the whole conversation.
- [Streaming](https://antarya.ai/docs/guides/streaming.md): Show the reply as it is written.
- [Counting tokens](https://antarya.ai/docs/guides/counting-tokens.md): Know the size of a conversation before you send it.
- [Sessions](https://antarya.ai/docs/guides/sessions.md): Let Antarya keep the history for you.
