Messages or raw prompts: picking between the two generation routes

People who run coding agents against a local llama.cpp server or a hosted compatible API often ask what exactly their tool is sending. Is it using the chat endpoint or the older completion one? Which sampling values does it pass, and do those override the settings they carefully chose when starting the server to keep the model focused?
Those questions come down to two endpoints that look similar and behave differently: POST /v1/chat/completions, which takes a list of role-tagged messages, and POST /v1/completions, which takes a raw text prompt and continues it. This article explains the difference, when each is the better choice, how to see what a tool really sends, and how parameters interact with server defaults.
Both endpoints are available on the keyless free-ai service used in the examples. This site is not affiliated with OpenAI; on OpenAI's own platform, check the current documentation for which models support which endpoint.
Frequently asked questions
What is the chat completions endpoint?
It accepts a list of messages, each with a role such as system, user or assistant, and returns the next assistant message. The server applies the model's chat template to turn the messages into the exact text the model sees.
What is the text completions endpoint?
It accepts a single prompt string and returns a continuation. No chat template is applied unless the server adds one. It is the older style of API and gives you direct control over the raw input.
How do the response shapes differ?
Chat responses put text in choices[0].message.content, or in delta.content when streaming. Text completion responses put it in choices[0].text. Parsers written for one will not read the other without changes.
Which is better for chat assistants and agents?
Chat completions. The template handles role separation correctly for the model, tools usually build on it, and system prompts work as intended. Most modern tooling assumes it.
When is the text endpoint the better choice?
For pure continuation tasks such as code completion from a prefix, filling in a document, or experiments where you want to control every token of the prompt, including custom formats. It also suits base models without chat tuning.
Do request parameters override server defaults?
Usually, yes. Most compatible servers use launch settings as defaults and let per-request values such as temperature or top_p take precedence. If your tool sends its own values, your server settings may never apply.
Does streaming work on both?
On the free endpoint here, yes. Both stream server-sent events ending with data: [DONE]. The chunk shapes differ in the same way as the full responses.
Is one endpoint being phased out?
Providers have shifted focus toward chat-style and newer APIs over time, and support for the old text endpoint varies by model. Check your provider's current documentation rather than assuming it is available everywhere.
Two ways to ask for text
Under the hood, a language model only ever continues text. The difference between the endpoints is who builds that text. With text completions, you do: the prompt string you send is, more or less, exactly what the model reads. With chat completions, the server does: it takes your messages and wraps them in the special tokens and markers the model was trained on.
That wrapping is called a chat template. It marks where the system instructions end, where the user turn starts and where the assistant should reply. Chat-tuned models rely on it heavily; send them a raw prompt without it and they may ramble, continue your question or ignore instructions.
Why templates matter
Each model family has its own template. Getting it wrong by hand is a common source of poor output, which is why the chat endpoint, where the server applies it for you, is the safer default.
Base versus chat models
A base model without chat tuning has no template to apply. For such models, the text endpoint is the natural interface.
What the model actually reads
Whichever endpoint you call, the model ends up reading one long sequence of tokens. With chat, that sequence includes role markers the server inserts; with text, it is your prompt as sent. Knowing this makes many puzzling behaviors less mysterious. A model that seems to ignore a system prompt on the text endpoint is not being stubborn; it simply never received the markers that tell it which part is an instruction.
Request and response side by side
The two requests below ask for the same thing. Notice the messages list versus the prompt string, and the different place the answer lives in each response.
Everything else, including max_tokens, temperature, stop and stream, works similarly on both. On the free endpoint, both accept up to 32,000 tokens of context and return up to 16,000.
Stop sequences are essential on the text endpoint
Without a chat template there is no natural end of turn, so the model keeps writing. A stop sequence such as a newline or a custom marker keeps continuations short.
from openai import OpenAI
client = OpenAI(base_url="https://api.apifreekeyopenai.com/v1", api_key="not-needed")
chat = client.chat.completions.create(
model="free-ai",
messages=[
{"role": "system", "content": "Answer in one short sentence."},
{"role": "user", "content": "What is a hash map?"},
],
max_tokens=60,
)
print("chat:", chat.choices[0].message.content)
text = client.completions.create(
model="free-ai",
prompt="A hash map is",
max_tokens=40,
stop=["\n"],
)
print("text:", "A hash map is" + text.choices[0].text)
When chat completions is the right tool
For assistants, agents, support bots, extraction and almost anything instruction-driven, chat is the better fit. System prompts behave as intended, multi-turn conversations are easy to represent, and structured output techniques assume it. Tool calling features, where supported, also build on the chat format.
If you are unsure, use chat. It is what most libraries, tutorials and coding assistants expect, and it protects you from template mistakes. Our guides on reliable JSON output and building a Discord bot both use it.
Stateless either way
Neither endpoint remembers anything between requests. With chat you resend the message history; with text you resend the whole prompt.
Token overhead of templates
Chat templates add a small number of tokens per message for role markers. For normal conversations the overhead is negligible, but in workloads with thousands of tiny messages, such as classification of short strings, it adds up. If you send huge batches of very short items, measure both endpoints with your real data and compare token counts reported in the usage field before deciding.
- Instructions and system prompts.
- Multi-turn conversations.
- Agents and tool use.
- Structured extraction and classification.
When the text endpoint still wins
Raw continuation shines for tasks that are naturally about finishing text. Code completion from a cursor position, filling the next row of a table, continuing a story in a fixed style or generating many variants of a pattern all map cleanly onto a prompt and a stop sequence.
It is also valuable for experiments. When you want to know exactly what the model reads, with no hidden template, the text endpoint shows you. Researchers comparing prompt formats or testing few-shot examples often prefer it for that transparency.
Fill-in style prompts
Some local coding tools use the text endpoint with a prefix and a stop marker for inline suggestions. They work well with short contexts and tight stop rules.
Few-shot patterns
A prompt with several input and output examples followed by a new input lets the model infer the pattern. On the text endpoint you control the separators exactly.

Finding out what your tool really sends
When an agent or editor extension talks to a compatible server, it may choose either endpoint and add its own sampling parameters. The only reliable way to know is to look at the traffic. Many local servers can log incoming requests in verbose mode; alternatively, point the tool at a tiny logging proxy on your machine.
The script below is a minimal proxy that prints each request body and forwards it unchanged. Run it, set your tool's base URL to http://localhost:8099/v1, and watch the console.
Non-streaming only
This proxy buffers responses, so turn off streaming in the tool while inspecting. It is a debugging aid, not something to leave running.
# pip install requests
import json, requests
from http.server import BaseHTTPRequestHandler, HTTPServer
UPSTREAM = "https://api.apifreekeyopenai.com" # or your llama.cpp server, e.g. http://127.0.0.1:8080
class Proxy(BaseHTTPRequestHandler):
def do_POST(self):
body = self.rfile.read(int(self.headers.get("Content-Length", 0)))
try:
print(self.path, json.dumps(json.loads(body), indent=2)[:3000])
except ValueError:
print(self.path, body[:500])
r = requests.post(UPSTREAM + self.path, data=body, timeout=300,
headers={"Content-Type": "application/json", "User-Agent": "debug-proxy/1.0"})
self.send_response(r.status_code)
self.send_header("Content-Type", r.headers.get("Content-Type", "application/json"))
self.end_headers()
self.wfile.write(r.content)
HTTPServer(("127.0.0.1", 8099), Proxy).serve_forever()Server defaults versus request parameters
A frequent surprise: you start a local server with a low temperature and conservative sampling to keep a model on task, yet the agent still produces wandering output. The likely reason is that the agent sends its own temperature, top_p or penalty values on each request, and most servers let request values override launch defaults.
Once you have seen the actual request body, you can fix this from either side. Configure the tool to send the values you want, or, if it allows, to omit sampling parameters so the server defaults apply. Some servers also offer options to clamp or ignore client-supplied values; check its documentation.
Parameters that differ by server
Options like min_p, repeat penalty or custom grammar exist on some servers and not others. Unknown fields may be ignored or rejected. See errors from compatible endpoints if a request fails after you add one.
Pinning values in the tool
Many coding agents and editor extensions have a settings file where you can set temperature, top_p and maximum output length for each configured model. Setting them there explicitly is often easier than fighting server defaults, and it keeps behavior consistent when you move the same tool between a local server and a hosted endpoint. Write the values down next to the base URL so the configuration stays self-explanatory.

Streaming both endpoints
Both endpoints stream as server-sent events. Each event line begins with data: and carries a JSON chunk; the stream ends with data: [DONE]. For chat, text arrives in choices[0].delta.content; for text completions, in choices[0].text.
If you switch a tool from one endpoint to the other, update the stream parser as well as the request builder. Mixed-up parsers are a classic cause of empty output with no error.
Reasoning mode
The free endpoint accepts an optional "reasoning": true field. Thinking happens before the visible answer, so allow a max_tokens of 2000 or more.
curl -sN https://api.apifreekeyopenai.com/v1/completions \
-H "Content-Type: application/json" \
-d '{"model":"free-ai","prompt":"Three colors of the rainbow:","max_tokens":30,"stream":true}'A quick decision guide
Default to chat completions for anything driven by instructions or conversation. Reach for text completions when you are continuing text, need exact control over the prompt, or are working with a base model. Whichever you use, keep the endpoint choice and parameters in configuration so a tool change does not require code edits.
If you want to try both without setting anything up, the keyless endpoint at https://api.apifreekeyopenai.com/v1 serves the same free-ai model on both routes, within per-IP limits of about one request per second and two concurrent requests. For a wider look at using it as a test target, see free APIs for testing.
Check provider support
Not every hosted model is available on the text endpoint. Before building on it, confirm support in your provider's documentation.
Migrating old code
Projects written years ago against the text endpoint can usually move to chat with modest changes: wrap the old prompt in a single user message, move any instructions into a system message, and update the response parser. Test the migration with a handful of saved prompts first, because chat-tuned models may answer more verbosely than the old continuation style, which can break downstream length assumptions.

Send a prompt to the keyless free-ai endpoint from the home page and see a reply in seconds, no sign-up needed.
Read also
- Why does an OpenAI-compatible endpoint throw internal server errors?
- How to run an always-on Discord bot on a VPS with an LLM API
- Are discounted OpenAI API credits from resellers worth the risk?
- How to add AI document analysis to a no-code or low-code web app
- Is there a free OpenAI-compatible API you can use for testing?