Endpoint
POST https://api.barqapi.com/v1/chat/completions
Request Body
| Parameter | Type | Required | Description |
model | string | ✅ Yes | Model ID (e.g. gpt-4o, claude-sonnet-4-6, deepseek-v4-pro) |
messages | array | ✅ Yes | Array of message objects with role and content |
temperature | number | No | Sampling temperature (0–2). Default: 1 |
max_tokens | integer | No | Maximum tokens in the response |
stream | boolean | No | Enable SSE streaming. Default: false |
top_p | number | No | Nucleus sampling. Default: 1 |
stop | string/array | No | Stop sequences |
Message Roles
| Role | Description |
system | Sets model behavior (first message only) |
user | End-user messages |
assistant | Model responses (for multi-turn conversations) |
Example Request
{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful Arabic-English translator."},
{"role": "user", "content": "Translate: 'Welcome to Saudi Arabia'"}
],
"temperature": 0.7,
"max_tokens": 200
}
Example Response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1718200000,
"model": "gpt-4o",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "مرحباً بكم في المملكة العربية السعودية"
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 12,
"total_tokens": 37
}
}