TypeScript SDK: Chat completions
Methods for POST /v1/chat/completions and its helpers.
import Syntic from '@syntic/sdk'
const client = new 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.countTokens | 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.
const result = await 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.
for await (const item of client.chat.completions.stream({
model: "Amara S1.2",
messages: [
{
role: "user",
content: "Tell me a story"
}
]
})) {
console.log(item)
}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.
const result = await client.chat.completions.parse({
model: "Amara Quick",
messages: [
{
role: "user",
content: "…"
}
],
response_format: zodResponseFormat(Ticket, 'ticket')
})chat.completions.countTokens
Count input tokens for a request body without running it. Maps to POST /v1/chat/completions/count_tokens.
const result = await client.chat.completions.countTokens({
model: "Amara S1.2",
messages: [
{
role: "user",
content: "Hello"
}
]
})Conventions
Every method accepts a final options object with headers, query, timeout, maxRetries and signal (an AbortSignal). List methods return pages that work with for await across all pages.
See the TypeScript SDK overview for installation, errors and retries.