Chat Completions

Generate text with large language models. Fully compatible with the OpenAI Chat Completions API — streaming and non-streaming.

Endpoint

POST https://api.agilecloud.ai/v1/chat/completions

Request Body

ParameterTypeRequiredDescription
modelstringYesModel name or alias (e.g., qwen-2.5-3b)
messagesarrayYesArray of message objects with role and content
streambooleanNoEnable server-sent events streaming. Default: false
temperaturenumberNoSampling temperature (0.0–2.0). Default: 1.0
max_tokensintegerNoMaximum tokens to generate
top_pnumberNoNucleus sampling threshold. Default: 1.0

Non-Streaming Example

curl https://api.agilecloud.ai/v1/chat/completions \
  -H "Authorization: Bearer $DIRECTAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-2.5-3b",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Explain HIPAA in one sentence."}
    ],
    "temperature": 0.7,
    "max_tokens": 256
  }'

Response

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "Qwen/Qwen2.5-3B-Instruct",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "HIPAA is a US federal law that protects..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 42,
    "total_tokens": 67
  }
}

Streaming Example

Set stream: true to receive server-sent events (SSE) as the model generates tokens:

curl https://api.agilecloud.ai/v1/chat/completions \
  -H "Authorization: Bearer $DIRECTAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-2.5-3b",
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": true
  }'

Each SSE event contains a delta:

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Available Models

See the Models page for a full list of chat models and their aliases.

Response Headers

  • X-Request-ID — Correlation ID for tracing and audit
  • Content-Type: text/event-stream — For streaming responses