OpenAI-compatible chat. The response arrives in the same HTTP request.
Endpoint
POST https://llm.dat.ai/v1/chat/completions
Authorization: Bearer YOUR_API_KEY
Content-Type: application/jsonRequest body
JSON object. For the full shape — including messages — see the example below.
| Field | Required | Description |
|---|---|---|
model | Yes | Model name, e.g. qwen3:1.7b |
messages | Yes | Objects with role and content (roles: user, assistant, system) |
stream | No | Default false. Set true for SSE streaming |
max_tokens, max_completion_tokens | No | Max tokens to generate |
temperature, top_p, stop, seed | No | Standard OpenAI sampling options |
tools, tool_choice | No | OpenAI function calling — see Function calling below |
datai | No | dat.ai built-in node tools — see Inference overview |
Optional header: X-Request-ID (correlation ID; server generates a UUID if omitted).
Function calling
Use tools and tool_choice for OpenAI function calling : declare functions the model can call, and optionally control selection with tool_choice (auto, none, required, or a specific function).
tools— array of{ "type": "function", "function": { "name", "description", "parameters" } }whereparametersis a JSON Schema objecttool_choice— whether/how the model picks a tool
These fields are forwarded to the node unchanged. They are not the same as datai.tools (net, fs), which turn on dat.ai built-in node capabilities.
Response
Non-streaming (200): standard OpenAI chat.completion:
{
"id": "chatcmpl-...",
"object": "chat.completion",
"model": "qwen3:1.7b",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "Hello!" },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 5,
"total_tokens": 15
}
}usage is present only when the node reports token counts.
Streaming: Content-Type: text/event-stream. Chunks follow the OpenAI streaming format; the stream ends with data: [DONE].
Errors
OpenAI-style JSON — see Authentication. Common cases:
| Status | Cause |
|---|---|
| 400 | Invalid JSON, missing model/messages, datai.tools + stream: true |
| 401 | Missing or invalid API key |
| 402 | Insufficient credits |
| 504 | Request timed out (max wait 180 seconds) |
Example
curl -sS -X POST "https://llm.dat.ai/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3:1.7b",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": false
}'