Skip to main content

Chat Completions

Creates a chat completion for the provided messages.

POST /v1/inference/chat/completions

Generate a chat-based completion (OpenAI-compatible, supports streaming). Here are examples of Python, JavaScript SDK, and cURL command that make an API request from your terminal:

Request Headers

Content-Type: "application/json"
Authorization: Bearer GRAVIXLAYER_API_KEY

Example Usage

chat-completions.sh
curl -X POST https://api.gravixlayer.com/v1/inference/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GRAVIXLAYER_API_KEY" \
-d '{
"model": "llama3.1:8b-instruct-fp16",
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}'

Response:

{
"id": "chatcmpl-638",
"object": "chat.completion",
"created": 1752093069,
"model": "llama3.1:8b-instruct-fp16",
"system_fingerprint": "fp_ollama",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 11,
"completion_tokens": 10,
"total_tokens": 21
}
}