% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/serve.R
\name{llama_serve_openai}
\alias{llama_serve_openai}
\title{Serve an OpenAI-compatible HTTP API for a local model}
\usage{
llama_serve_openai(
  model_path,
  port = 11434L,
  n_ctx = 4096L,
  n_gpu_layers = -1L,
  model_id = NULL,
  host = "127.0.0.1",
  template = NULL,
  max_tokens = 512L,
  ...
)
}
\arguments{
\item{model_path}{Path to a GGUF model file.}

\item{port}{Port to listen on. Default \code{11434} (the Ollama port, so
clients pointed at a local Ollama work unchanged).}

\item{n_ctx}{Context size for the loaded model.}

\item{n_gpu_layers}{Layers to offload to GPU (\code{-1} = all).}

\item{model_id}{Identifier reported in \code{/v1/models} and echoed in
responses. Defaults to the model file's base name.}

\item{host}{Address to bind. Default \code{"127.0.0.1"} (local only).}

\item{template}{Chat template string, or \code{NULL} to use the model's
built-in template.}

\item{max_tokens}{Default \code{max_new_tokens} when a request omits it.}

\item{...}{Reserved for future options.}
}
\value{
Invisibly \code{NULL}. Blocks serving until \code{drogonR::dr_stop()}
  is called (typically from another process or an interrupt).
}
\description{
Loads a GGUF model once and exposes it over an OpenAI-compatible HTTP
API so any OpenAI client (OpenCode, ellmer, the `openai` Python SDK, …)
can talk to it. Implements `GET /v1/models` and
`POST /v1/chat/completions` (both blocking and `stream = true`). The
HTTP/SSE layer is provided by \pkg{drogonR}; generation runs through
llamaR's streaming API (\code{\link{llama_gen_begin}} /
\code{\link{llama_gen_next}} / \code{\link{llama_gen_end}}).
}
\details{
The server is single-sequence: requests are handled one at a time on the
main R thread (each streamed token is one event-loop pump). This is meant
for a single local user/agent, not concurrent load.

\code{drogonR} is an optional dependency (\code{Suggests}); install it
with \code{install.packages("drogonR")} (or from its repository) before
calling this function.
}
\examples{
\dontrun{
llama_serve_openai("model.gguf", port = 11434L)
# In another shell, point any OpenAI client at
#   http://127.0.0.1:11434/v1
# e.g. GET /v1/models and POST /v1/chat/completions
}
}
\seealso{
[llama_gen_begin], [llama_generate]
}
