% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/serve_anthropic.R
\name{llama_serve_anthropic}
\alias{llama_serve_anthropic}
\title{Serve an Anthropic Messages API-compatible endpoint for a local model}
\usage{
llama_serve_anthropic(
  model_path,
  port = 11435L,
  n_ctx = 32768L,
  n_gpu_layers = -1L,
  split_mode = "layer",
  model_id = NULL,
  host = "127.0.0.1",
  max_tokens = 1024L,
  strip_thinking = TRUE,
  enable_thinking = FALSE,
  vision_model_path = NULL,
  mmproj_path = NULL,
  vision_n_ctx = 8192L,
  vision_debug = FALSE,
  ...
)
}
\arguments{
\item{model_path}{Path to a GGUF model file. Use a tool-calling-capable model
(e.g. Qwen, Llama-3.x, Mistral/Mixtral) for Claude Code to work well.}

\item{port}{Port to listen on. Default \code{11435}.}

\item{n_ctx}{Context size for the loaded model. Default \code{32768}: Claude
Code sends a large system prompt (tool definitions + rules, often
20k+ tokens), so a small context window rejects every request. Raise it
further for long sessions if the model supports it.}

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

\item{split_mode}{Multi-GPU split strategy, passed to
\code{\link{llama_load_model}}: \code{"layer"} (default) splits the model
across all GPUs by layer, \code{"none"} loads it whole onto a single GPU,
\code{"row"} splits tensors by row. On a multi-GPU host the \code{"layer"}
default can hang on the Vulkan backend (cross-device copies); use
\code{"none"} to pin the model to one card when it fits in that card's VRAM.}

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

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

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

\item{strip_thinking}{Drop \code{<think>...</think>} reasoning blocks from the
response text before returning (default \code{TRUE}). Reasoning models
(DeepSeek-R1, QwQ) emit these inline; the Anthropic API never puts reasoning
in the text, so Claude Code expects clean content. Non-reasoning models
(Qwen, Mistral, Llama) emit no such blocks, so this is a no-op for them. Set
\code{FALSE} to keep the reasoning visible (e.g. for debugging).}

\item{enable_thinking}{Ask the chat template to enable the model's reasoning
mode (default \code{FALSE}). Hybrid thinking models (Qwen3.5, etc.) otherwise
spend their whole token budget inside an unclosed \code{<think>} block and
never reach the answer, which \code{strip_thinking} then turns into an empty
reply. Kept \code{FALSE} so Claude Code gets direct answers and fast tool
calls; set \code{TRUE} only if you also raise \code{max_tokens} enough for
the model to finish reasoning. No effect on non-thinking models.}

\item{vision_model_path}{Optional path to a SECOND, vision-capable GGUF model
(e.g. Qwen2-VL). When given together with \code{mmproj_path}, the server
uses a \emph{caption-then-reason} pipeline: a request carrying an image is
first passed to this vision model, which DESCRIBES the image (focused on the
user's question); that description is then spliced into the conversation as
text and answered by the main \code{model_path} model - so the stronger text
model does the reasoning, tool calls, and streaming, while the vision model
only provides "eyes". \code{NULL} (default) keeps the server text-only and
image blocks are dropped, as before.}

\item{mmproj_path}{Path to the clip projector (mmproj) GGUF paired with
\code{vision_model_path}. Required to enable vision; must match that model.}

\item{vision_n_ctx}{Context size for the vision model's own context
(default \code{8192}). Vision turns (screenshot + question) are short, so a
small KV cache keeps both models within VRAM.}

\item{vision_debug}{If \code{TRUE}, log each vision caption to the server
console (not returned to the client). Default \code{FALSE}: the caption is
internal, the user sees only the text model's final answer.}

\item{...}{Reserved for future options.}
}
\value{
Invisibly \code{NULL}. Blocks serving until interrupted.
}
\description{
Loads a GGUF model once and exposes it over an Anthropic Messages
API-compatible HTTP API, so Claude Code (or any Anthropic SDK client) can run
against local inference. Point Claude Code at it with
\code{ANTHROPIC_BASE_URL=http://127.0.0.1:<port>} and any non-empty
\code{ANTHROPIC_API_KEY}.
}
\details{
Implements \code{POST /v1/messages} (blocking and \code{stream = true}) and a
minimal \code{GET /v1/models}. Tool use is supported: \code{tools} in the
request are passed through the tool-aware chat layer
(\code{\link{llama_chat_build}}), generation is grammar-constrained, and the
model's output is parsed back into \code{tool_use} blocks
(\code{\link{llama_chat_parse}}).

Single-sequence: requests are handled one at a time on the main R thread,
like \code{\link{llama_serve_openai}}. Meant for one local user/agent.
}
\examples{
\dontrun{
llama_serve_anthropic("Qwen3-14B-Q8_0.gguf", port = 11435L)
# Then, in another shell:
#   ANTHROPIC_BASE_URL=http://127.0.0.1:11435 \
#   ANTHROPIC_API_KEY=sk-local claude
}
}
\seealso{
[llama_serve_openai], [llama_chat_build], [llama_chat_parse]
}
