Chat API
One endpoint for every conversational model on the platform — with streaming, tool calling, structured JSON output and optional persistent memory.
Create a completion
POST
/v1/chat/completionsSend a list of messages and receive the assistant's reply. The request shape is identical across all models, so switching models is a one-line change.
curl https://api.tapotik.ai/v1/chat/completions \
-H "Authorization: Bearer $TAPOTIK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tapotik-2-pro",
"messages": [
{ "role": "system", "content": "You are a concise support agent." },
{ "role": "user", "content": "How do credits roll over?" }
],
"temperature": 0.4,
"max_tokens": 600
}'const completion = await client.chat.completions.create({
model: "tapotik-2-pro",
messages: [
{ role: "system", content: "You are a concise support agent." },
{ role: "user", content: "How do credits roll over?" },
],
temperature: 0.4,
max_tokens: 600,
});
console.log(completion.choices[0].message.content);
console.log(completion.usage); // { input_tokens, output_tokens, credits }Request parameters
| Parameter | Type | Description |
|---|---|---|
model | string · required | Model ID, e.g. tapotik-2-pro or router/auto for smart routing. |
messages | array · required | Conversation history. Roles: system, user, assistant, tool. |
stream | boolean · default false | Stream tokens as server-sent events instead of a single response. |
temperature | number · 0–2 · default 0.7 | Higher values increase creativity; lower values increase determinism. |
max_tokens | integer | Hard cap on generated tokens. Defaults to the model maximum. |
tools | array | JSON-schema tool definitions the model may call. |
response_format | object | Set { "type": "json_schema" } with a schema for guaranteed structured output. |
memory_id | string | Attach a persistent memory store so context survives across sessions. |
metadata | object | Up to 16 key-value pairs echoed back in webhooks and the audit log. |
Streaming
With stream: true the endpoint returns text/event-stream chunks. The final event is [DONE] and includes usage totals on the preceding chunk.
const stream = await client.chat.completions.create({
model: "router/auto",
messages: [{ role: "user", content: "Summarize this ticket thread." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}Tool calling
Describe functions with JSON Schema and the model will return a tool_calls array when it wants to use one. Execute the call on your side, then append the result as a tool message and continue the loop.
const completion = await client.chat.completions.create({
model: "tapotik-2-pro",
messages,
tools: [
{
type: "function",
function: {
name: "get_invoice",
description: "Fetch an invoice by ID",
parameters: {
type: "object",
properties: { invoice_id: { type: "string" } },
required: ["invoice_id"],
},
},
},
],
});
const call = completion.choices[0].message.tool_calls?.[0];
// -> { id, function: { name: "get_invoice", arguments: '{"invoice_id":"inv_231"}' } }Available models
| Model | Context | Best for | Credits / 1K tokens |
|---|---|---|---|
tapotik-2-pro | 200K | Flagship quality, tools and reasoning | 1.0 |
tapotik-2-flash | 128K | High-volume, latency-sensitive workloads | 0.25 |
router/auto | varies | Smart routing to the best model per request | metered by routed model |
openai/gpt-4o | 128K | Frontier model via unified API | 2.0 |
anthropic/claude-4-sonnet | 200K | Long-context analysis and writing | 1.8 |
router/auto requires a Pro plan or above. It routes each request based on prompt complexity, latency targets and your monthly budget — teams typically save 40–60% on credits with no quality loss.See also: rate limits for throughput per plan, and errors for retry guidance.