Python SDK: Chat completions
Methods for POST /v1/chat/completions and its helpers.
from syntic import Syntic
client = Syntic() # reads SYNTIC_API_KEY| Method | Endpoint | Returns |
|---|---|---|
chat.completions.create | POST /v1/chat/completions | ChatCompletion |
chat.completions.stream | POST /v1/chat/completions | ChatCompletionStream (context manager / async iterable) |
chat.completions.parse | POST /v1/chat/completions | ParsedChatCompletion[T] |
chat.completions.count_tokens | POST /v1/chat/completions/count_tokens | TokenCount with input_tokens, remaining_tokens |
Methods
chat.completions.create
Send a conversation and get the reply. Pass stream=True to get an iterator of chunks instead. Maps to POST /v1/chat/completions.
result = client.chat.completions.create(
model="Amara S1.2",
messages=[{"role": "user", "content": "Hello"}],
max_tokens=300,
)chat.completions.stream
Stream with a helper that accumulates text, tool calls and usage, and exposes the final message when done. Maps to POST /v1/chat/completions.
with client.chat.completions.stream(
model="Amara S1.2",
messages=[{"role": "user", "content": "Tell me a story"}],
) as stream:
for event in stream:
print(event)chat.completions.parse
Structured output from a Pydantic model (Python) or Zod schema (TypeScript); returns the parsed object on message.parsed. Maps to POST /v1/chat/completions.
result = client.chat.completions.parse(
model="Amara Quick",
messages=[{"role": "user", "content": "…"}],
response_format=Ticket,
)chat.completions.count_tokens
Count input tokens for a request body without running it. Maps to POST /v1/chat/completions/count_tokens.
result = client.chat.completions.count_tokens(
model="Amara S1.2",
messages=[{"role": "user", "content": "Hello"}],
)Conventions
Every method accepts extra_headers, extra_query, extra_body and timeout keyword arguments, and has an async twin on AsyncSyntic. List methods return pages that iterate across all pages automatically.
See the Python SDK overview for installation, errors and retries.