Request carries model + role-tagged messages + sampling knobs; response carries assistant content + finish_reason + a usage block; streaming swaps the JSON body for SSE delta chunks.
Picture sending a structured letter to an assistant. The envelope says which assistant to deliver it to (the model name). Inside the envelope, every paragraph is labeled with who is speaking: system rules first, then a back and forth between user and assistant. You also include a sticky note with knobs like 'do not exceed 500 words' and 'be a little creative'. The assistant writes a reply with three things: the actual text, a stamp saying why she stopped writing, and a meter showing how many words you used in total. If you ticked the streaming box, instead of one finished letter you get a stack of postcards arriving one piece at a time.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
The chat completions endpoint is the common request format of hosted LLM serving. OpenAI's shape, introduced in 2023, became the de facto industry standard because every client SDK and agent framework was written against it. Every major provider (Anthropic, Google, Mistral, DeepSeek) ships either an OpenAI-compatible endpoint or a thin adapter. Every open-source serving stack (vLLM, TensorRT-LLM, SGLang) ships one too, so self-hosted deployments work with existing client code after a base-URL change.
The request schema in detail
A chat completions request body has three components.
model, a string identifying which model to use. Hosted APIs accept model IDs such asgpt-5.5andclaude-sonnet-4-6. Self-hosted vLLM accepts the model path or alias configured at startup.messages, an array of message objects, each with aroleandcontent. The roles aredeveloperorsystem(instructions and persona),user(input from the caller),assistant(prior model output, used for multi-turn context), andtool(results from function calls being fed back). Content is text by default; for multimodal endpoints it is an array of typed parts (text, image, audio).- Sampling and shaping parameters,
temperature(rescales logits),top_p(nucleus truncation),max_completion_tokens(hard cap on generated tokens, including reasoning tokens),stop(sequences that terminate generation),presence_penaltyandfrequency_penalty(discourage repetition),seed(best-effort reproducibility), andtools/tool_choicefor function calling.
Multimodal content arrays
When content is an array, each entry has a type field (text, image_url, input_audio). GPT-5.5 and Claude Opus 4.7 both accept this shape. Image parts can carry a base64 data URL or a remote URL. Vision models turn each image into vision tokens; the count depends on the image size and the provider, and those tokens are billed as input in the usage block.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- OpenAI's Chat Completions API defines the reference schema; every other provider adopts it or offers an adapter.
- Anthropic's native Messages API uses a similar structure with role-tagged messages, and its usage block adds cache_creation_input_tokens and cache_read_input_tokens fields. Anthropic also offers an OpenAI SDK compatibility endpoint, mainly for testing and comparing models.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does the chat completions contract handle multimodal inputs?
The content field per message becomes an array of typed parts: text parts, image parts (with base64 or URL), and audio parts on audio-capable models. GPT-5.5, Claude Opus 4.7 and Gemini 3.1 Pro all use this shape. Image tokenization is provider-specific, and image tokens count toward input usage.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Conflating the legacy completions endpoint with chat completions. Chat completions is structured around role-tagged messages, not a single prompt string, and finish_reason matters for tool-call dispatch.
60 second bullets to scan on the way to the call.
Required request fields: model, messages, optional sampling knobs
The message roles (developer or system, user, assistant, tool)
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.