Chat Completions
Create a chat completion using the Vexrail API. This endpoint is compatible with the OpenAI chat completions format and supports both streaming and non-streaming responses.
Endpoint
POST /v1/chat/completions
Authentication
Requires x-publishable-key and x-secret-key headers. See Authentication.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | The model to use for the completion. See Models for available options. |
messages | array | Yes | An array of message objects representing the conversation history. |
stream | boolean | No | If true, the response is streamed as Server-Sent Events. Default: false. |
temperature | number | No | Sampling temperature between 0 and 2. Higher values make output more random. |
max_tokens | number | No | Maximum number of tokens to generate in the response. |
top_p | number | No | Nucleus sampling parameter. An alternative to temperature. |
Message Object
| Field | Type | Description |
|---|---|---|
role | string | The role of the message author: system, user, or assistant. |
content | string | The content of the message. |
Non-Streaming Response
Example Request
curl -X POST https://api.vexrail.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "x-publishable-key: pk_live_your_key" \
-H "x-secret-key: sk_live_your_key" \
-H "x-conversation-id: conv-123" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What tools can help me manage my projects?"}
]
}'
Example Response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "There are several great project management tools available..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}
Streaming Response
To receive a streaming response, set stream: true in the request body. The response uses Server-Sent Events (SSE).
Example Request
curl -X POST https://api.vexrail.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "x-publishable-key: pk_live_your_key" \
-H "x-secret-key: sk_live_your_key" \
-H "x-conversation-id: conv-123" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "user", "content": "What tools can help me manage my projects?"}
],
"stream": true
}'
Example Response
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1700000000,"model":"gpt-4o-mini","choices":[{"index":0,"delta":{"role":"assistant","content":"There"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1700000000,"model":"gpt-4o-mini","choices":[{"index":0,"delta":{"content":" are"},"finish_reason":null}]}
...
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1700000000,"model":"gpt-4o-mini","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
Conversation Tracking
Include the x-conversation-id header to group messages into a conversation. This enables:
- Better contextual relevance for product promotions.
- Conversation analytics in your dashboard.
If you omit this header, each request is treated as an independent interaction.
Promotions in Responses
When monetization is enabled on your project and relevant advertiser products match the conversation context, the AI response may include contextual product recommendations. These are included naturally within the response content -- no additional parsing is needed on your end.
Error Codes
| Status | Description |
|---|---|
400 | Invalid request body (missing model, empty messages, etc.) |
401 | Authentication failed |
403 | Domain not verified or insufficient credit balance |
500 | Internal server error |
See Errors for details.