Python SDK: Chat completions

⚠️
Preview — this feature is being built; the design below is the spec.

Methods for POST /v1/chat/completions and its helpers.

from syntic import Syntic
 
client = Syntic()  # reads SYNTIC_API_KEY
MethodEndpointReturns
chat.completions.createPOST /v1/chat/completionsChatCompletion
chat.completions.streamPOST /v1/chat/completionsChatCompletionStream (context manager / async iterable)
chat.completions.parsePOST /v1/chat/completionsParsedChatCompletion[T]
chat.completions.count_tokensPOST /v1/chat/completions/count_tokensTokenCount 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.

Was this page helpful?