Completions
Creates a completion for the provided prompt.
POST /v1/inference/completions
Classic completion endpoint (OpenAI-compatible).
Request Headers
Content-Type: "application/json"
Authorization: Bearer GRAVIXLAYER_API_KEY
Example Usage
- cURL
- Python
- JavaScript
completions.sh
curl -XPOST http://api.gravixlayer.com/v1/inference/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GRAVIXLAYER_API_KEY" \
-d '{
"model": "llama3.1:8b-instruct-fp16",
"stream": false,
"prompt": "What comes after Monday?"
}'
Response:
{
"id": "cmpl-713",
"object": "text_completion",
"created": 1752094856,
"model": "llama3.1:8b-instruct-fp16",
"system_fingerprint": "fp_ollama",
"choices": [
{
"text": "The days of the week follow in this order:\n\n1. Sunday\n2. Monday\n3. Tuesday\n4. Wednesday\n5. Thursday\n6. Friday\n7. Saturday\n\nSo, if today is Monday, then tomorrow would be Tuesday!",
"index": 0,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 52,
"total_tokens": 67
}
}
completions.py
import os
import json
from openai import OpenAI
client = OpenAI(
base_url="https://api.gravixlayer.com/v1/inference",
api_key=os.environ.get("GRAVIXLAYER_API_KEY"),
)
completion = client.completions.create(
model="llama3.1:8b-instruct-fp16",
prompt="What comes after Monday?",
)
print(json.dumps(completion.model_dump(), indent=2))
Response:
{
"id": "cmpl-520",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"text": "Thursday.\n\nHere is a complete list of days of the week:\n\n1. Sunday\n2. Monday\n3. Tuesday\n4. Wednesday\n5. Thursday\n6. Friday\n7. Saturday"
}
],
"created": 1752096161,
"model": "llama3.1:8b-instruct-fp16",
"object": "text_completion",
"system_fingerprint": "fp_ollama",
"usage": {
"completion_tokens": 41,
"prompt_tokens": 15,
"total_tokens": 56,
"completion_tokens_details": null,
"prompt_tokens_details": null
}
}
completions.js
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: process.env.GRAVIXLAYER_API_KEY,
baseURL: "https://api.gravixlayer.com/v1/inference"
});
async function main() {
const completion = await openai.completions.create({
model: "llama3.1:8b-instruct-fp16",
prompt: "What comes after Monday?",
});
console.log(completion);
}
main();
Response:
{
id: 'cmpl-496',
object: 'text_completion',
created: 1752096196,
model: 'llama3.1:8b-instruct-fp16',
system_fingerprint: 'fp_ollama',
choices: [
{
text: 'The days of the week, in order, are:\n' +
'\n' +
'1. Sunday\n' +
'2. Monday\n' +
'3. Tuesday\n' +
'4. Wednesday\n' +
'5. Thursday\n' +
'6. Friday\n' +
'7. Saturday\n' +
'\n' +
'So, after Monday comes Tuesday!',
index: 0,
finish_reason: 'stop'
}
],
usage: { prompt_tokens: 15, completion_tokens: 47, total_tokens: 62 }
}