POST /v1/chat/completionsCreate chat completion
Full reference for POST /v1/chat/completions: request body fields, response schema, streaming format, and tool calling examples.
Creates a model response for a conversation. Send the full message history in each request — the API is stateless, so the model only sees what you include in messages.
POST https://api.tase.app/v1/chat/completionsAuthenticate with your API key in the Authorization: Bearer tase_sk_... header. See the Authentication guide for details.
Request body
Required fields
- **model** (string, required) — ID of the model to use. Currently tase-8b. List available IDs with GET /v1/models.
- **messages** (array, required) — The conversation so far, ordered oldest to newest. Each entry is a message object.
Message objects
- **role** (string, required) — One of system, user, assistant, or tool.
- **content** (string, required) — The text of the message. For tool messages, this is the JSON-encoded result your code produced.
- **tool_call_id** (string, required for role tool) — The ID of the tool call this message responds to, taken from the assistant message that requested it.
Optional fields
- **stream** (boolean, optional) — When true, the response is sent incrementally as server-sent events instead of a single JSON body. Defaults to false.
- **temperature** (number, optional) — Sampling temperature between 0 and 2. Lower values make output more deterministic, higher values more varied.
- **max_tokens** (integer, optional) — Upper bound on the number of tokens generated for the completion.
- **tools** (array, optional) — Function definitions the model may call. Each entry declares a function with a name, description, and JSON Schema parameters.
- **tool_choice** (string or object, optional) — Controls tool use: auto lets the model decide, none disables tools, required forces a tool call, and an object of the form {"type": "function", "function": {"name": "..."}} forces one specific function.
- **response_format** (object, optional) — Constrains the output format, for example to request structured JSON output.
Example request
curl https://api.tase.app/v1/chat/completions \
-H "Authorization: Bearer $TASE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tase-8b",
"messages": [
{ "role": "system", "content": "You are a concise assistant." },
{ "role": "user", "content": "Summarize why sleep matters in two sentences." }
],
"temperature": 0.7,
"max_tokens": 200
}'Response
- **id** (string) — Unique identifier for this completion.
- **object** (string) — Always chat.completion for non-streaming responses.
- **created** (integer) — Unix timestamp of when the completion was created.
- **model** (string) — The model that produced the response.
- **choices** (array) — The generated completions. Each choice has an index, a message, and a finish_reason.
- **choices[].message** (object) — The assistant message: role, content, and tool_calls when the model requested tools.
- **choices[].finish_reason** (string) — Why generation stopped: stop (natural end), length (hit max_tokens), or tool_calls (the model wants your code to run a tool).
- **usage** (object) — Token accounting: prompt_tokens, completion_tokens, and total_tokens.
Example response
{
"id": "chatcmpl-9f3a2b1c8d7e6f5a",
"object": "chat.completion",
"created": 1784937600,
"model": "tase-8b",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Sleep is when your body repairs tissue and your brain consolidates memory. Skipping it degrades focus, mood, and long-term health faster than almost any other habit."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 38,
"total_tokens": 66
}
}Tool calls
When you pass tools and the model decides to use one, the assistant message contains a tool_calls array instead of final text, and finish_reason is tool_calls:
{
"id": "chatcmpl-2c4e6a8b0d1f3e5c",
"object": "chat.completion",
"created": 1784937655,
"model": "tase-8b",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_7d1a9c3b5e2f4a68",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Istanbul\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 74,
"completion_tokens": 21,
"total_tokens": 95
}
}Run the function in your own code, then continue the conversation by appending the assistant message followed by a tool message whose tool_call_id matches the call ID. The model then produces a final answer that incorporates the result.
Streaming
Set "stream": true to receive the completion as server-sent events. Each event is a data: line containing a chunk object; the text arrives incrementally in choices[].delta.content. The stream ends with a literal data: [DONE] line.
data: {"id":"chatcmpl-9f3a2b1c8d7e6f5a","object":"chat.completion.chunk","created":1784937600,"model":"tase-8b","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-9f3a2b1c8d7e6f5a","object":"chat.completion.chunk","created":1784937600,"model":"tase-8b","choices":[{"index":0,"delta":{"content":"Sleep is when"},"finish_reason":null}]}
data: {"id":"chatcmpl-9f3a2b1c8d7e6f5a","object":"chat.completion.chunk","created":1784937600,"model":"tase-8b","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]Concatenate the deltas
delta.content value in order. The final chunk carries the finish_reason and an empty delta.Errors