Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Serving and the APIs

glyd serve google/gemma-4-12B-it

serve loads the model and answers on http://127.0.0.1:8000. The chat page is at /. run starts the same server.

After the release script, a background service is also running on 127.0.0.1:11434. It loads a model when a request names it and unloads it when idle, and holds two at a time by default:

glyd pull gemma4:12b
curl localhost:11434/v1/chat/completions -H 'Content-Type: application/json' \
  -d '{"model":"gemma4:12b","messages":[{"role":"user","content":"hi"}]}'
glyd ps                  # what is loaded, and when it is unloaded
glyd stop gemma4:12b     # unload it now (glyd stop --all)
glyd service install     # run it at every login; glyd service runs it in this terminal

The service loads only models already pulled, and glyd run chats through it where it runs. Its options (--keep-alive, --max-loaded, --port) and what it leaves open are in the service page.

Options

FlagWhat
--port NThe port. Without it, 8000, then each next port up to 8020 that is free. With it, that port or a refusal.
--host HListen on H. Without it, only this computer, and a request whose Host or Origin is not this computer's is refused (421, 403). With it, those checks are off.
--context NThe context in tokens (--ctx is the same). Without it, what fits: Models has each family's default.
--users NHow many requests run at once, 4 by default: 1 to 8 on the lossless Qwen3 engine; up to 64 for Gemma 4, Qwen3.8 dense, Nemotron-H, DeepSeek-V4, Muse Spark, Kimi-K3 and GLM-5.3-Flash on one GPU, as many as its memory holds. Other engines take one request at a time and the rest wait in order.
--with MODEL2A second model served by the same process on the same GPU, on --with-port N (else the next free port after the first's). Each has its own server; the first loads and takes up to half of the memory left for its sequences, then the second loads in the rest.
--host-memory GIBThe computer's memory a mixture of experts may use for its experts.
MODEL:LEVELA level: Choosing a level.

The key

GLYD_API_KEY=secret glyd serve google/gemma-4-12B-it

With a key, every path under /v1 needs Authorization: Bearer secret. /, /health and /stats stay open. Put the key in the environment: a --api-key flag shows in ps. With --host set to an address other than this computer's, anyone who can reach it can use the model, and the traffic is plain HTTP: use a key and an SSH tunnel or a VPN.

What it answers

PathWhat
POST /v1/chat/completionsOpenAI chat, JSON or a stream. Tools, response_format (json_object, json_schema), tool_choice, and vLLM's guided_* fields.
POST /v1/completionsA plain completion; suffix makes it fill in the middle for a model that has the tokens.
POST /v1/responsesOpenAI's Responses API, stateless.
POST /v1/messages, /v1/messages/count_tokensAnthropic's Messages API, for the Anthropic SDKs and Claude Code: thinking blocks, tools, streaming.
/api/chat, /api/generate, /api/tags, /api/show, /api/ps, /api/versionOllama's API, for programs that talk to Ollama. --ollama-port N listens on Ollama's port too, where it is free.
GET /v1/models, /v1/models/IDThe one model. id is the name you started it with.
GET /health{"status":"ok"}, no key needed.
GET /v1/glyd/infoWhat the server is and holds: model, level, precision, device, limits, memory.
GET /statsThe scheduler's counts (lossless engine).

A first request with curl:

curl -s http://127.0.0.1:8000/v1/chat/completions -H 'Content-Type: application/json' \
  -d '{"messages":[{"role":"user","content":"Say pong."}],"max_tokens":64}'

A thinking model thinks before it answers. To turn that off for a request, send "chat_template_kwargs": {"enable_thinking": false}; run takes --no-think.

Errors are OpenAI's shape: {"error": {"message", "type", "param", "code"}}. A prompt past the context is 400 with the code context_length_exceeded; a wrong key is 401 invalid_api_key.

The full reference

Every field the server reads, refuses or ignores, the states from loading to failed, the exit codes and the status file are in the API reference (the contract, glyd-serve/1). The background service is in its own page.