Chat Service#
- class saia_python.chat.ChatService(session: requests.Session, base_url: str, *, retry: RetryPolicy | bool | None = None)[source]#
Access the
/chat/completionsendpoint.- Parameters:
session – A
requests.Sessionwith auth headers configured.base_url – The SAIA API base URL.
- completions(model: str, messages: list[dict], *, temperature: float | None = None, top_p: float | None = None, max_tokens: int | None = None, stream: bool = False, retry: RetryPolicy | bool | None = None, **kwargs) dict | SSEStream[source]#
Send a chat completion request.
- Parameters:
model – Model identifier (e.g.
"meta-llama-3.1-8b-instruct").messages – List of message dicts with
"role"and"content"keys.temperature – Sampling temperature (0–2).
top_p – Nucleus sampling parameter (0–1).
max_tokens – Maximum tokens to generate.
stream – If
True, return a generator yielding chunks.**kwargs – Additional parameters forwarded to the API.
- Returns:
the API response dict, with an extra
"_rate_limits"key — a JSON-serializable dict of the current rate-limit headers (seeRateLimitInfo). Whenstream=True: anSSEStream— iterate it for the response chunks; itsrate_limitsattribute exposes the same dict (available immediately, from the response headers).- Return type:
When
stream=False