The Chat Completions API: the interface that became a standard
OpenAI's Chat Completions API is the messages-based interface most of the industry now speaks. Here's how it works — roles, parameters, streaming, and tool calls.
If you build with LLMs, you'll spend a lot of time talking to the Chat Completions API. It started as OpenAI's interface and became a de-facto standard — Groq, OpenRouter, local runtimes, and many others speak the same shape, so learning it once pays off everywhere.
The core idea
You send a list of messages, each tagged with a role — system, user, or assistant — and the model returns the next assistant message. The system message sets behaviour, the conversation history gives context, and the model continues it. That's the whole mental model.
const res = await client.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a concise assistant.' },
{ role: 'user', content: 'Explain embeddings in one line.' },
],
temperature: 0.3,
});
console.log(res.choices[0].message.content);The parameters worth knowing
- temperature — how random the output is; low for deterministic tasks, higher for creative ones.
- max_tokens — a cap on the response length (and your cost).
- streaming — receive the response token-by-token for a responsive UI instead of waiting for the whole thing.
- tools / function calling — let the model request that your code run a function, so it can fetch data or take actions.
- response_format — ask for strict JSON when you're going to parse the output.
Why it matters
Because so many providers copy this interface, coding against it keeps you portable: switching models is often just a base URL and a model string. That portability is a feature — design for it.
Learn the messages-and-roles model once, and half the LLM ecosystem starts speaking your language.