Zenaique

Give the shape of an OpenAI compatible chat completions request and response.

Flashcard·Easy·4.0 · 0·~30s·Asked atAi4bharatCitadelKrutrim·Relevant atOpenAI
Attempt it
TL;DR

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.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

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.

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 as gpt-5.5 and claude-sonnet-4-6. Self-hosted vLLM accepts the model path or alias configured at startup.
  • messages, an array of message objects, each with a role and content. The roles are developer or system (instructions and persona), user (input from the caller), assistant (prior model output, used for multi-turn context), and tool (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_penalty and frequency_penalty (discourage repetition), seed (best-effort reproducibility), and tools / tool_choice for 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.

The response schema and finish_reason as a contract
Streaming: SSE framing and TTFT
Why every stack speaks the OpenAI shape
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

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.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow does the chat completions contract handle multimodal inputs?
A

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.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

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.

Sign in to see all red flags and common mistakes.

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)

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is the KV cache in transformer inference?
Flashcard·Easy