Skip to main content

Endpoint

  • POST /v1/chat/completions

What it does

OpenAI-compatible subset of chat.completions:
  • non-streaming: JSON (application/json)
  • streaming: SSE (text/event-stream) with data: ... events and a final data: [DONE]

Built-in tools via datai.tools (service extension)

This endpoint accepts datai.tools (not part of the OpenAI spec) to enable built-in tool access:
{
  "datai": {
    "tools": {
      "net": true,
      "fs": true,
      "webview": true
    }
  }
}
  • datai.tools.net: enable network/HTTP tools.
  • datai.tools.fs: enable filesystem tools.
  • datai.tools.webview: enable browser/webview tools.
Important rule:
  • Tools cannot be used with streaming: if stream: true and datai.tools is present, the server returns 400.

Request body

Validated:
  • model (string, required)
  • messages (array, required, non-empty)
Accepted fields include: stream, max_tokens, max_completion_tokens, temperature, top_p, stop, seed, tools, tool_choice, datai.tools. Minimal request:
{
  "model": "qwen3:1.7b",
  "messages": [{ "role": "user", "content": "Hello!" }],
  "stream": false
}

Response (non-streaming)

{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "created": 1730000000,
  "model": "qwen3:1.7b",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "..." },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 1,
    "completion_tokens": 2,
    "total_tokens": 3
  }
}
usage is included only if token counters are available.

Streaming (SSE)

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1730000000,"model":"qwen3:1.7b","choices":[{"index":0,"delta":{"role":"assistant","content":"He"},"finish_reason":null}]}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1730000000,"model":"qwen3:1.7b","choices":[{"index":0,"delta":{"content":"llo"},"finish_reason":null}]}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1730000000,"model":"qwen3:1.7b","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Errors (OpenAI-style)

{ "error": { "message": "...", "type": "...", "param": null } }

curl examples

Non-streaming:
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
  }'
Streaming (SSE):
curl -N -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":"Spell HELLO"}],
    "stream": true
  }'
Tools (non-streaming only):
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":"Open https://example.com and summarize the page"}],
    "stream": false,
    "datai": { "tools": { "net": true, "webview": true } }
  }'