# Conversations and system prompts (/docs/entwickler/conversations)

> Hold multi-turn conversations, write system prompts that work and keep the history short, with a chatbot loop in Python and JavaScript.

A chat completion takes a list of messages and returns the next one. To continue a conversation, you send the whole history with each request. A system prompt steers the answers, and a short history keeps long conversations fast and affordable.

The examples use `gpt-swiss` [Schweiz], which answered in one to three seconds in our tests. Any model from [Models](/docs/entwickler/models) works the same way. All examples were run against the live API on 11.11.2026.

## Message roles
| Role | Written by | Use it for |
|---|---|---|
| `system` | You, the developer | Standing instructions: who the model is, tone, format, limits. Send it first. |
| `user` | Your user | The question, or the text the model should work on. |
| `assistant` | The model | Earlier answers. You send them back so that the model knows what it already said. |
| `tool` | Your code | The result of a function call, see `tools` in [Request body](/docs/entwickler/chat-completions#fields). |

Write instructions as `system`, not `developer`. In our tests, `developer` worked on some models and returned `500` on others, for example `mistral-small-swiss`.

## Multi-turn conversations
The API is stateless: it doesn't remember earlier requests. Every request must carry the whole conversation so far, oldest message first. To continue, append the model's answer as an `assistant` message, append the next `user` message, and send the full list again.

**curl**

The second turn of the conversation, with the first answer in the history:

```bash
curl https://api.peakprivacy.ch/v1/ai/chat/completions \
  -H "Authorization: Bearer $PEAKPRIVACY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "model": "gpt-swiss",
    "messages": [
      {"role": "system", "content": "You are the internal assistant of Alpenblick Treuhand AG. Write short, friendly English."},
      {"role": "user", "content": "Draft a one-sentence reminder for Luca: the Q3 report for Seeblick GmbH is due on 15 October."},
      {"role": "assistant", "content": "Hi Luca, just a friendly reminder that the Q3 report for Seeblick GmbH is due on 15 October."},
      {"role": "user", "content": "Make it more formal and add that Nadia can help."}
    ]
  }'
```

**Python**

```python
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://api.peakprivacy.ch/v1/ai",
    api_key=os.environ["PEAKPRIVACY_API_KEY"],
)

messages = [
    {"role": "system", "content": "You are the internal assistant of Alpenblick Treuhand AG. Write short, friendly English."},
    {"role": "user", "content": "Draft a one-sentence reminder for Luca: the Q3 report for Seeblick GmbH is due on 15 October."},
]

first = client.chat.completions.create(model="gpt-swiss", messages=messages)
reply = first.choices[0].message.content
print("1:", reply)

# Add the answer and the next question, then send the whole conversation again.
messages.append({"role": "assistant", "content": reply})
messages.append({"role": "user", "content": "Make it more formal and add that Nadia can help."})

second = client.chat.completions.create(model="gpt-swiss", messages=messages)
print("2:", second.choices[0].message.content)
```

**JavaScript**

```js
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.peakprivacy.ch/v1/ai",
  apiKey: process.env.PEAKPRIVACY_API_KEY,
});

const messages = [
  { role: "system", content: "You are the internal assistant of Alpenblick Treuhand AG. Write short, friendly English." },
  { role: "user", content: "Draft a one-sentence reminder for Luca: the Q3 report for Seeblick GmbH is due on 15 October." },
];

const first = await client.chat.completions.create({ model: "gpt-swiss", messages });
const reply = first.choices[0].message.content;
console.log("1:", reply);

// Add the answer and the next question, then send the whole conversation again.
messages.push({ role: "assistant", content: reply });
messages.push({ role: "user", content: "Make it more formal and add that Nadia can help." });

const second = await client.chat.completions.create({ model: "gpt-swiss", messages });
console.log("2:", second.choices[0].message.content);
```

Output of the Python and JavaScript versions:

```text
1: Hi Luca, just a friendly reminder that the Q3 report for Seeblick GmbH is due on 15 October.
2: Please be reminded that the Q3 report for Seeblick GmbH is due on 15 October, and should you require assistance, Nadia is available to help.
```

The second answer still names Seeblick GmbH and the date because both are in the history. Without the first two messages, the model wouldn't know which reminder you mean.

Because your code holds the history, you decide what the model sees. You can store it in your own database, shorten or edit it before the next request, or send it to a different model.

Send back only `role` and `content` of an answer. Reasoning models also return `reasoning_content` ([Reasoning](/docs/entwickler/reasoning#read)), but the next turn doesn't need it.

## System prompts that work
A good system prompt settles five things:

- **Role and audience.** Who the model is and for whom it works.
- **Task and limits.** What it should do and what it should leave alone.
- **Format.** Length, language, tone, lists or prose.
- **Uncertainty.** What to do when it doesn't know: say so, ask back, or point to a person.
- **Facts.** The model knows nothing about your organisation. Give it the names, rules and deadlines it needs.

The help desk below uses this prompt:

```text
You are the internal help desk of Alpenblick Treuhand AG, a fiduciary firm in Zurich.
Answer in at most three sentences.
If a question needs company-specific facts you don't have, say so and suggest asking Mira in Office Management.
```

- **Be concrete.** "At most three sentences" works better than "be brief".
- **Separate rules from material.** Rules go in the system prompt, the text to work on goes in a `user` message.
- **Test with real questions**, including the ones the model should decline or hand over.
- **Assume users can read it.** Users can often get a model to repeat its system prompt, so keep secrets out.
- **Keep personal data out.** `"anonymize": true` doesn't process `system` messages, see [Anonymisation](/docs/entwickler/anonymisation#limits).

## Temperature
`temperature` sets how much answers vary, from 0 to 2. The default is 0.7.

| Value | Good for |
|---|---|
| `0` to `0.3` | Help desk answers, extraction, classification |
| `0.7` | Everyday writing |
| `1` and above | Brainstorming, several variants of a text |

Even at `0`, two runs of the same request can give different answers. Some models ignore `temperature` or use a fixed value, see [Request body](/docs/entwickler/chat-completions#fields).

## Keep the history short
Every request sends the whole history again, so every turn costs more input tokens than the one before. In the help desk session below, `usage.prompt_tokens` grew from 121 to 223 in three short turns. Long histories also slow down answers, and a history longer than the model's context window fails with `400` or, depending on the model, `500`, see [The model rejects the request](/docs/entwickler/errors#model-rejected).

- **Keep the last messages.** Send the system prompt plus the most recent messages. The chatbot below keeps 20.
- **Summarise older turns.** Ask the model for a short summary of the conversation so far and send it instead of the older messages.
- **Start over** when the topic changes.
- **Send long documents once.** Include a document only in the turn that needs it, not in every later request.

## A chatbot in the terminal
A complete help desk bot: it reads questions from the terminal, keeps the history, trims it and prints the prompt size after each answer. Type `exit` or an empty line to quit.

**Python**

```python
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://api.peakprivacy.ch/v1/ai",
    api_key=os.environ["PEAKPRIVACY_API_KEY"],
)

MODEL = "gpt-swiss"
SYSTEM_PROMPT = (
    "You are the internal help desk of Alpenblick Treuhand AG, a fiduciary firm in Zurich. "
    "Answer in at most three sentences. "
    "If a question needs company-specific facts you don't have, say so and suggest asking Mira in Office Management."
)
MAX_MESSAGES = 20  # recent messages to keep, besides the system prompt

def trim(history):
    """Keep the system prompt and the most recent messages, starting with a user message."""
    recent = history[1:][-MAX_MESSAGES:]
    while recent and recent[0]["role"] != "user":
        recent.pop(0)
    return history[:1] + recent

messages = [{"role": "system", "content": SYSTEM_PROMPT}]

while True:
    question = input("You: ").strip()
    if question in ("", "exit"):
        break

    messages.append({"role": "user", "content": question})
    messages = trim(messages)

    completion = client.chat.completions.create(model=MODEL, messages=messages, temperature=0.3)
    answer = completion.choices[0].message.content
    messages.append({"role": "assistant", "content": answer})

    print(f"Bot: {answer}")
    print(f"     ({completion.usage.prompt_tokens} prompt tokens)\n")
```

**JavaScript**

```js
// Run as an ES module, e.g. chat.mjs
import readline from "node:readline";
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.peakprivacy.ch/v1/ai",
  apiKey: process.env.PEAKPRIVACY_API_KEY,
});

const MODEL = "gpt-swiss";
const SYSTEM_PROMPT =
  "You are the internal help desk of Alpenblick Treuhand AG, a fiduciary firm in Zurich. " +
  "Answer in at most three sentences. " +
  "If a question needs company-specific facts you don't have, say so and suggest asking Mira in Office Management.";
const MAX_MESSAGES = 20; // recent messages to keep, besides the system prompt

// Keep the system prompt and the most recent messages, starting with a user message.
function trim(history) {
  const recent = history.slice(1).slice(-MAX_MESSAGES);
  while (recent.length && recent[0].role !== "user") recent.shift();
  return [history[0], ...recent];
}

let messages = [{ role: "system", content: SYSTEM_PROMPT }];
const rl = readline.createInterface({ input: process.stdin });

process.stdout.write("You: ");
for await (const line of rl) {
  const question = line.trim();
  if (question === "" || question === "exit") break;

  messages.push({ role: "user", content: question });
  messages = trim(messages);

  const completion = await client.chat.completions.create({ model: MODEL, messages, temperature: 0.3 });
  const answer = completion.choices[0].message.content;
  messages.push({ role: "assistant", content: answer });

  console.log(`Bot: ${answer}`);
  console.log(`     (${completion.usage.prompt_tokens} prompt tokens)\n`);
  process.stdout.write("You: ");
}
rl.close();
```

A session:

```text
You: Draft a two-line out-of-office note for Nadia. She is back on 20 October.
Bot: I’m currently out of the office and will return on 20 October. For urgent matters, please contact Mira in Office Management.
     (121 prompt tokens)

You: Now the same in German.
Bot: Ich bin derzeit nicht im Büro und bin ab dem 20. Oktober wieder erreichbar.
Für dringende Angelegenheiten wenden Sie sich bitte an Mira in der Office Management.
     (165 prompt tokens)

You: Who do I ask about parking at our office?
Bot: I don’t have the specific contact for parking inquiries on hand—please ask Mira in Office Management, who can point you to the right person.
     (223 prompt tokens)

You: exit
```

"Now the same in German" works only because the earlier note is in the history. The third answer follows the system prompt's rule for unknown company facts.

For a bot that shows the answer while it is written, see [Streaming](/docs/entwickler/streaming).

## Good to know
- **One history per conversation.** Requests are independent, so conversations only mix if your code mixes them. Key each history by user and session.
- **Your application holds the history.** Store, protect and delete it like any other user data.
- **German answers use ss.** Chat completion answers have `ß` replaced by `ss`.
- **Failed requests.** If a request fails, your list ends with an unanswered question. After a `429`, a `500` or a network error, send the same list again with backoff, see [Retries](/docs/entwickler/errors#retry). If the model rejected the request, for example because the history is too long, shorten the history before you send it again.

## See also
- [Chat completions](/docs/entwickler/chat-completions)
- [Streaming](/docs/entwickler/streaming)
- [Getting JSON back](/docs/entwickler/json-output)
- [Reasoning](/docs/entwickler/reasoning)
