When a llamafile runs in server mode, it exposes the HTTP APIs inherited from llama-server, the server component of llama.cpp. The default base address is http://127.0.0.1:8080, and the server provides OpenAI-compatible APIs under /v1, so any app written for the OpenAI API can talk to your local model by changing its base URL.
Start the server
Add the --server argument to a llamafile to run it in server mode. The simplest form uses the default port, 8080:
./Qwen3.5-0.8B-Q8_0.llamafile --server
Use --host and --port to change where it listens. The docs give this example, which makes the server reachable from other machines on the network and moves it to port 8081:
./llava-v1.6-mistral-7b-Q4_K_M.llamafile --server --host 0.0.0.0 --port 8081
The --port parameter specifies a different port from the default one, 8080. If you serve a model to be used by an AI agent or agentic framework, the docs say to add the --jinja parameter and choose a context size that is large enough but still fits your memory, for example --ctx-size 64000.
Call it from another app
With the server running, send a chat completion request. The docs example uses the placeholder model name local-model:
curl http://127.0.0.1:8080/v1/chat/completions -H 'Content-Type: application/json' -d '{"model": "local-model", "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Write a limerick about llamas."}]}'
The model field is required by the OpenAI-style schema even when only one model is loaded, and clients commonly use a placeholder such as local-model; set --alias if you want a stable model name in requests and responses. GET /v1/models lists model metadata and capabilities. From Python, the OpenAI SDK reads its base URL and API key from environment variables: set the base URL to http://127.0.0.1:8080/v1 and the key to any non-empty value, because the SDK requires a non-empty API key value even when the llamafile server does not require authentication. Then create the client with client = OpenAI() and call client.chat.completions.create(model="local-model", messages=[{"role": "user", "content": "Hello!"}]), and read the reply from response.choices[0].message.content.
Try it: four checks from server to reply
| Check | What you should see | If you do not see it |
|---|---|---|
| Server starts | The llamafile process stays running with --server |
Check the terminal output for an error, then run the file again |
| Models list | curl http://127.0.0.1:8080/v1/models returns the model |
Check the server is still running and the port is 8080 |
| Chat completion | The curl request returns JSON with a limerick about llamas | Check the model field is local-model and the URL ends in /v1/chat/completions |
| App connected | Another app pointed at http://127.0.0.1:8080/v1 gets answers |
Check the app’s base URL ends in /v1 and its key is non-empty |
Expected result. We checked the Mozilla llamafile docs page on running a llamafile, which gives the –server, –host, –port, –jinja, and –ctx-size flags, and the Mozilla llamafile API page, which gives the default base address http://127.0.0.1:8080, the POST /v1/chat/completions curl example, the GET /v1/models endpoint, and the OpenAI SDK setup. We did not start a llamafile server or call its API on this machine.
Limits
This guide covers server mode and the OpenAI-compatible chat endpoint only. Running a llamafile without any mode flag already starts a server in combined mode, so use --server when you want the server without the terminal chat. The supported fields and behavior come from the llama.cpp version bundled into a particular llamafile release and can change between releases. Start with the default host binding, which listens on localhost only, and change it only if you need to access the server from another machine; when you do, configure --api-key or --api-key-file so reachable clients still need authentication, sending the key as an Authorization: Bearer header or an X-Api-Key header. We did not test any of this ourselves.
Sources
- Mozilla llamafile docs — Running a llamafile — –server mode, –host and –port with the 8081 example, –jinja and –ctx-size 64000 for agents, combined mode default
- Mozilla llamafile docs — API server — default base http://127.0.0.1:8080, OpenAI-compatible APIs under /v1, chat completions curl example, GET /v1/models, –api-key, OpenAI SDK environment variables
- llamafile README on GitHub — single-file executable that runs locally with no installation, quick-start download and run commands
