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
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model name or alias (e.g., qwen-2.5-3b) |
| messages | array | Yes | Array of message objects with role and content |
| stream | boolean | No | Enable server-sent events streaming. Default: false |
| temperature | number | No | Sampling temperature (0.0–2.0). Default: 1.0 |
| max_tokens | integer | No | Maximum tokens to generate |
| top_p | number | No | Nucleus 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 auditContent-Type: text/event-stream— For streaming responses