Skip to main content
The /v1/chat/completions endpoint provides conversational AI capabilities using a chat message format. It’s fully compatible with OpenAI’s Chat Completions API.

Endpoint

Request Format

Required Parameters

string
required
Model identifier. Can be the model path, alias (set via --alias), or any string when using a single model.
array
required
Array of message objects representing the conversation history. Each message has:
  • role (string): One of system, user, or assistant
  • content (string): The message content
For multimodal models, content can be an array with text and image parts.

Optional Parameters

number
default:"0.8"
Sampling temperature between 0 and 2. Higher values make output more random, lower values more deterministic.
number
default:"0.95"
Nucleus sampling parameter. Only tokens with cumulative probability up to top_p are considered.
number
default:"40"
Limits token selection to the K most probable tokens. Set to 0 to disable.
number
default:"0.05"
Minimum probability threshold relative to the most likely token.
number
default:"-1"
Maximum number of tokens to generate. -1 means unlimited.
boolean
default:"false"
Whether to stream partial message deltas using Server-Sent Events.
array
Array of strings. Generation stops when any of these sequences are encountered.
number
default:"0.0"
Penalize tokens based on whether they appear in the text so far. Range: -2.0 to 2.0.
number
default:"0.0"
Penalize tokens based on their frequency in the text. Range: -2.0 to 2.0.
number
default:"1.1"
Penalize repetition of token sequences.
number
default:"-1"
Random seed for reproducible outputs. Use -1 for random.
object
Control output format:
  • {"type": "json_object"} - Force valid JSON output
  • {"type": "json_schema", "schema": {...}} - Constrain to JSON schema
array
Array of tool/function definitions for function calling. Requires --jinja flag.
string | object
Control tool selection: auto, none, or {"type": "function", "function": {"name": "tool_name"}}

llama.cpp-Specific Parameters

number
default:"0"
Enable Mirostat sampling. 0 = disabled, 1 = Mirostat 1.0, 2 = Mirostat 2.0
number
default:"5.0"
Mirostat target entropy (τ parameter).
number
default:"0.1"
Mirostat learning rate (η parameter).
string
default:"auto"
Controls reasoning/thinking tags:
  • none - No parsing, raw output in content
  • deepseek - Extract thoughts to reasoning_content field
  • deepseek-legacy - Keep tags in content while populating reasoning_content
boolean
default:"false"
Force reasoning models to always output thinking process.
boolean
default:"true"
Reuse KV cache from previous requests when possible for faster processing.

Request Examples

Response Format

Standard Response

string
Unique identifier for the completion.
string
Always "chat.completion" for non-streaming responses.
number
Unix timestamp of when the completion was created.
string
The model used for the completion.
array
Array of completion choices. Each choice contains:
  • index (number) - Choice index
  • message (object) - The generated message with role and content
  • finish_reason (string) - Why generation stopped: stop, length, or tool_calls
  • logprobs (object | null) - Token probabilities if requested
object
Token usage statistics:
  • prompt_tokens (number) - Tokens in the prompt
  • completion_tokens (number) - Tokens generated
  • total_tokens (number) - Sum of prompt and completion tokens
object
Performance metrics (llama.cpp specific):
  • prompt_n (number) - Prompt tokens processed
  • prompt_ms (number) - Time spent on prompt
  • predicted_n (number) - Tokens generated
  • predicted_ms (number) - Time spent generating
  • cache_n (number) - Tokens reused from cache

Example Response

Streaming Responses

When stream: true, the server sends Server-Sent Events (SSE):

Function Calling

To enable function calling, start the server with --jinja:
Then define tools in your request:
The model will respond with tool calls:

Reasoning Models

For models with reasoning capabilities (e.g., DeepSeek-R1), thoughts are extracted to reasoning_content:
Set reasoning_format: "none" to get raw output without reasoning extraction.

Multi-turn Conversations

Include the full conversation history in the messages array:

Performance Tips

  1. Enable prompt caching: Set cache_prompt: true (default) to reuse KV cache across requests
  2. Use streaming: Enable stream: true for better perceived latency
  3. Adjust context size: Use -c flag to set appropriate context window for your use case
  4. GPU acceleration: Use --n-gpu-layers to offload layers to GPU
  5. Parallel requests: Use --parallel to handle multiple concurrent requests

Error Responses

Common error codes:
  • 400 - Invalid request (missing/invalid parameters)
  • 401 - Authentication failed
  • 503 - Server unavailable (model still loading)