> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gatelit.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Conversations

> Multi-turn chat with automatic history management. The SDK tracks messages so you don't have to.

`Conversation` maintains message history across turns. You call `send()` with a user message, and it appends both the user turn and the assistant response to `messages` — ready for the next turn.

## Basic multi-turn

```ts theme={null}
const client = new GatelitClient({
  gatewayUrl: "https://gateway.yourapp.com",
  getToken: async () => ({ token: "sk_live_...", scheme: "GatelitKey" }),
})

const conv = client.conversation({ model: "openai/gpt-4o" })

const r1 = await conv.send("What is the capital of France?")
console.log(r1.content)
// → "The capital of France is Paris."

const r2 = await conv.send("What is its population?")
console.log(r2.content)
// → "Paris has a population of about 2.1 million..."

// The full history is sent automatically on every turn
console.log(conv.messages)
// [
//   { role: "user", content: "What is the capital of France?" },
//   { role: "assistant", content: "The capital of France is Paris." },
//   { role: "user", content: "What is its population?" },
//   { role: "assistant", content: "Paris has a population..." },
// ]
```

## Streaming conversations

Use `conv.stream()` for token-by-token output with history tracking:

```ts theme={null}
const conv = client.conversation({
  model: "anthropic/claude-3-5-sonnet-20241022",
})

let fullResponse = ""

for await (const chunk of conv.stream("What are the top 3 JavaScript frameworks?")) {
  process.stdout.write(chunk.delta)
  fullResponse += chunk.delta
}

// The assistant response is appended to conv.messages automatically
// after the stream completes
console.log(`Conversation has ${conv.messages.length} messages`)
```

## System prompts

```ts theme={null}
const conv = client.conversation({
  model: "openai/gpt-4o",
  systemPrompt: "You are a sarcastic pirate. Keep responses under 20 words.",
})

const r = await conv.send("What's the weather like?")
// → "Sunny enough to make a landlubber squint, arr."
```

The system prompt is prepended to **every** request — it's not part of `conv.messages`.

## Controlling generation

Max tokens and temperature set at conversation creation for convenience, or override per turn with `client.chat()` directly:

```ts theme={null}
const conv = client.conversation({
  model: "google/gemini-2.5-flash",
  maxTokens: 200,
  temperature: 0.3,
})

const r = await conv.send("Summarize this document...")
```

## Resetting

```ts theme={null}
conv.reset()
console.log(conv.messages) // []
```

Clears the full history. Useful when the user starts a new topic or when context gets too long.

## Accessing the underlying client

`Conversation` wraps `GatelitClient` — you can still use it directly for non-conversation requests:

```ts theme={null}
const conv = client.conversation({ model: "openai/gpt-4o" })
await conv.send("Hello")

// Use the client directly for a one-off request
const classification = await client.chatJson({...})
```
