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

# Chat-Completions

> Rufe /chat/completions mit dem Python-SDK auf.

**Methode**: `client.generate_text()` (übertrage verarbeitete Chunks mit `client.stream_chat()`).

### Beispiel

```python theme={null}
chat = client.generate_text({
    "model": "openai/gpt-4o-mini",
    "messages": [
        {"role": "system", "content": "You are helpful."},
        {"role": "user", "content": "Write a limerick about lighthouses."},
    ],
    "temperature": 0.5,
})
```

### Datenstrom

```python theme={null}
for chunk in client.stream_chat({
    "model": "openai/gpt-4o-mini",
    "messages": [{"role": "user", "content": "Stream a story"}],
}):
    if chunk.get("text"):
        print(chunk["text"], end="", flush=True)
```

### Wichtige Parameter

* `model` (erforderlich): ID des Zielmodells.
* `messages` (erforderlich): geordnete Nachrichten mit den Rollen `system|user|assistant|tool`; der Inhalt kann aus Text oder Teilen bestehen.
* Sampling: `temperature` (0–2), `top_p` (0–1), `top_k` (>=1), `seed` (optionale Ganzzahl).
* Länge und Penalties: `max_output_tokens` (Ganzzahl), `presence_penalty` und `frequency_penalty` (-2 bis 2), `stop` (string|string\[]).
* Tools: `tools` (Definitionen), `tool_choice` (auto/none/bestimmtes Tool), `max_tool_calls` (Ganzzahl), `parallel_tool_calls` (boolesch).
* Logprobs: `logprobs` (boolesch), `top_logprobs` (0–20).
* Ausgabe: `response_format` (json/text), `metadata` (durchgereichtes Objekt), `stream` (boolesch), `service_tier`.
* Gateway-Erweiterungen: `usage` (boolesch, um Nutzungsdaten anzufordern), `meta` (boolesch, um den Meta-Block einzuschließen).

### Rückgabe

`ChatCompletionsResponse`

```json theme={null}
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-3.5-turbo-0125",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello there, how may I assist you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 12,
    "total_tokens": 21
  }
}
```

Oder SSE-Zeilen beim Streaming

```
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-3.5-turbo-0125","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-3.5-turbo-0125","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-3.5-turbo-0125","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":9,"completion_tokens":12,"total_tokens":21}}

data: [DONE]
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.