LLM Serving API
When the inference feature is enabled, JustAPI exposes an OpenAI-compatible API for LLM serving.
Enabling Inference
Section titled “Enabling Inference”# Build with inference supportcargo build --release --features inference
# Run with a modeljustapi serve --model my-model.ggufChat Completions
Section titled “Chat Completions”POST /v1/chat/completionsContent-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
Section titled “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
Section titled “Streaming”POST /v1/chat/completionsContent-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
Section titled “Completions”POST /v1/completionsContent-Type: application/json
{ "model": "my-model", "prompt": "Once upon a time,", "max_tokens": 100, "temperature": 0.8}Embeddings
Section titled “Embeddings”POST /v1/embeddingsContent-Type: application/json
{ "model": "my-model", "input": "The quick brown fox jumps over the lazy dog"}Model Management
Section titled “Model Management”GET /v1/models{ "object": "list", "data": [ { "id": "my-model", "object": "model", "created": 1721827200, "owned_by": "justapi" } ]}Sampling Parameters
Section titled “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
Section titled “See Also”- Inference Overview — Architecture and components
- GPU & CUDA Setup — Hardware configuration
- Scheduling & Batching — Performance optimization