When the inference feature is enabled, JustAPI exposes an OpenAI-compatible API for LLM serving.
Enabling Inference
# Build with inference support
cargo build --release --features inference
# Run with a model
justapi serve --model my-model.gguf
Chat Completions
POST /v1/chat/completions
Content-Type: application/json
{
"model": "my-model",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is Rust?"}
],
"temperature": 0.7,
"max_tokens": 256,
"stream": false
}
Response
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1721827200,
"model": "my-model",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Rust is a systems programming language..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 58,
"total_tokens": 82
}
}
Streaming
POST /v1/chat/completions
Content-Type: application/json
{
"model": "my-model",
"messages": [{"role": "user", "content": "Count to 5."}],
"stream": true
}
Streaming response (SSE):
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"1"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"2"},"finish_reason":null}]}
data: [DONE]
Completions
POST /v1/completions
Content-Type: application/json
{
"model": "my-model",
"prompt": "Once upon a time,",
"max_tokens": 100,
"temperature": 0.8
}
Embeddings
POST /v1/embeddings
Content-Type: application/json
{
"model": "my-model",
"input": "The quick brown fox jumps over the lazy dog"
}
Model Management
GET /v1/models
{
"object": "list",
"data": [
{
"id": "my-model",
"object": "model",
"created": 1721827200,
"owned_by": "justapi"
}
]
}
Sampling Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
temperature |
float | 1.0 |
Sampling temperature |
top_p |
float | 1.0 |
Nucleus sampling threshold |
top_k |
int | 40 |
Top-k sampling |
max_tokens |
int | 256 |
Maximum tokens to generate |
stop |
list[str] | [] |
Stop sequences |
presence_penalty |
float | 0.0 |
Penalize new tokens |
frequency_penalty |
float | 0.0 |
Penalize frequent tokens |
See Also
- Inference Overview — Architecture and components
- GPU & CUDA Setup — Hardware configuration
- Scheduling & Batching — Performance optimization