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

# Best practices

> Keep ThinkFeel integrations clear, efficient, and secure.

## Maintain conversation context

To keep multi-turn conversations consistent, always include previous messages.

```javascript theme={null}
const conversation = [];

// First exchange
conversation.push({ role: 'user', content: 'What do you do for fun?' });
let response = await api.generate(personaId, conversation);
conversation.push({ role: 'assistant', content: response.result.finalReply });

// Second exchange - includes full history
conversation.push({ role: 'user', content: 'That sounds cool!' });
response = await api.generate(personaId, conversation);
```

## Trim long conversations

For very long conversations, consider truncating older messages to reduce latency.

```javascript theme={null}
function trimConversation(messages, maxMessages = 20) {
  if (messages.length <= maxMessages) return messages;
  return messages.slice(-maxMessages);
}
```

## Never expose API keys

<Warning>Do not put API keys in client-side or public code.</Warning>

Do not hardcode keys:

```javascript theme={null}
const response = await fetch(url, {
  headers: {
    'x-api-key': 'abc123...',
  },
});
```

Use managed environment variables or secrets:

```javascript theme={null}
const response = await fetch(url, {
  headers: {
    'x-api-key': process.env.THINKFEEL_API_KEY,
  },
});
```
