Chat completions
Send a conversation to a model and get the answer as JSON or a stream, with anonymisation and the Responses endpoint.
Send a conversation to a model and get its next message, as one JSON response or as a stream.
POST https://api.peakprivacy.ch/v1/ai/chat/completions
POST https://api.peakprivacy.ch/v1/ai/completions (same endpoint)Example
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": "deepseek-v4-flash",
"messages": [
{"role": "system", "content": "You write short internal notes."},
{"role": "user", "content": "Draft a two-line reminder about the expense report deadline."}
],
"temperature": 0.3
}'The Python and JavaScript snippets further down reuse this client.
Request body
| Name | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model id from GET /v1/ai/models. |
messages | array | Yes | The conversation, oldest first. Each message has a role (system, user, assistant or tool) and content. Use system, not developer: some models return 500 for developer. See Conversations. |
stream | boolean | No | true returns Server-Sent Events, see Streaming. Default false. |
temperature | number | No | 0 to 2, at most two decimals. Default 0.7. Some models ignore it or use a fixed value. |
top_p | number | No | 0 to 1, at most two decimals. Some models ignore it. |
max_tokens | integer | No | At least 1. Capped at the model's max_tokens. Most models ignore it; in our tests only gpt-swiss applied it. Don't rely on it to limit cost. |
tools | array | No | Function definitions in the OpenAI format. Calls come back in choices[].message.tool_calls. Not every model supports tools: see Tool calling. |
reasoning | object | No | effort: how much the model thinks first. Wins over reasoning_effort. Which models apply it: Reasoning. Unsupported values are dropped without an error. |
reasoning_effort | string | No | Same as reasoning.effort. |
anonymize | boolean | No | PeakPrivacy field. Runs every message except system messages through the anonymiser and turns streaming off. Default false. See Anonymisation. |
Ignored fields. random_seed (integer) and safe_prompt (boolean) are validated, then ignored by current models. instructions and file_uuids are passed on, but don't rely on them. Send instructions as a system message. Don't send file_uuids: the completions endpoints don't load uploaded files, and in our tests deepseek-v4-flash returned 500 with it. Send the text in messages, see Use a file in a completion. Other fields, such as stop, n, response_format, tool_choice, seed, presence_penalty, frequency_penalty, user or max_completion_tokens, are dropped without an error. Use max_tokens instead of max_completion_tokens.
Response
{
"id": "5cb77078-8a1a-4b7d-9b0d-1f2d7f5e0d3a",
"object": "chat.completion",
"created": 1781500000,
"model": "deepseek-v4-flash",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": { "role": "assistant", "content": "Reminder: please submit your expense report by Friday." }
}
],
"usage": { "prompt_tokens": 24, "completion_tokens": 18, "total_tokens": 42 }
}| Field | Type | Description |
|---|---|---|
id | string | Request id. Quote it when you contact PeakPrivacy about a request. |
model | string | PeakPrivacy id of the model that answered. |
choices[].message | object | The answer, with role and content, plus tool_calls if the model called a tool. ß in content is replaced by ss. |
choices[].finish_reason | string | Why generation stopped, for example stop, length or tool_calls. |
usage | object | prompt_tokens, completion_tokens and total_tokens. |
Streaming
With "stream": true, the response is a stream of Server-Sent Events. Streaming has complete consumers that detect an early end, handle errors and cancel a stream.
curl --no-buffer 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": "mistral-small-swiss",
"stream": true,
"messages": [{"role": "user", "content": "Greet me in three different ways."}]
}'Each event is a data: line with one chat.completion.chunk:
- Text arrives in
choices[].delta.content. Reasoning models also senddelta.reasoning_content. See Reasoning › Streaming for a current limitation. - The chunk that ends the text has
finish_reasonset. - Every chunk has
usage. Depending on the model it shows zeros or running counts, so read it from the last chunk, whosechoicesarray can be empty. idchanges from chunk to chunk.data: [DONE]ends a complete stream.
data: {"id":"...","object":"chat.completion.chunk","created":1781500000,"model":"mistral-small-swiss","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"},"finish_reason":null}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
…
data: {"id":"...","object":"chat.completion.chunk","created":1781500001,"model":"mistral-small-swiss","choices":[{"index":0,"delta":{"content":""},"finish_reason":"stop"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
data: {"id":"...","object":"chat.completion.chunk","created":1781500001,"model":"mistral-small-swiss","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":9,"total_tokens":21}}
data: [DONE]Errors found before the stream starts come back as a normal JSON response with a 4xx or 5xx status, so check the status before you read the body as a stream. Failures after the first chunk arrive as an event: error, see Errors during a stream.
Anonymisation
With "anonymize": true, the PeakPrivacy anonymiser processes every message except system messages before the model sees them. Keep personal data out of the system prompt. Anonymisation explains what the anonymiser replaces and where its limits are.
Such a request never streams: you get one JSON response even with "stream": true. An SDK call with streaming turned on then returns no chunks and no error, so leave stream off. The OpenAI SDKs don't know the field, so send it like this:
Add the field to the JSON body:
{
"model": "deepseek-v4-flash",
"anonymize": true,
"messages": [{"role": "user", "content": "Summarise: Luca Meier asks Nadia for the Q3 figures by Friday."}]
}The Responses endpoint doesn't anonymise its input.
Responses endpoint
POST /v1/ai/responses returns an OpenAI Responses object instead of a chat completion. Models with meta.capabilities.responses set to false don't support it, see Endpoint support.
| Name | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model id. |
input | string or array | Yes | The prompt as text, or an array of input items. |
instructions | string | No | Instructions for the model, like a system message. |
max_output_tokens | integer | No | At least 1. Behaves like max_tokens. |
temperature, top_p, stream, tools | No | As in Request body. | |
reasoning | object | No | effort and summary. See Reasoning. |
curl https://api.peakprivacy.ch/v1/ai/responses \
-H "Authorization: Bearer $PEAKPRIVACY_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"model": "deepseek-v4-flash",
"instructions": "Answer in one short paragraph.",
"input": "List three principles of data protection."
}'The response is the model's Responses object, with model set to the PeakPrivacy model id. The text is in the output array, in content items of type output_text. With "stream": true, each event has an event: line with its type and a data: line. Text arrives in response.output_text.delta events, and a response.completed event ends the stream. There is no data: [DONE] line.
Errors
400for an unknownmodel, atemperatureortop_pout of range or with more than two decimals, or amax_tokensbelow 1. See 400 Bad Request.400with codeunsupported_endpointif the model doesn't support the endpoint, also with"stream": true. See Model doesn't support the endpoint.400or, depending on the model,500withtrace_idif the model rejects the request, for example because the prompt exceeds its context window. See The model rejects the request.500withtrace_idif the model fails or takes longer than 120 seconds without streaming. See Timeouts.