OpenAI chat messages builder
The OpenAI chat completions endpoint takes a messages array where the system
prompt is itself a message with the system role, usually first, followed by
user and assistant turns. Typing that JSON by hand and getting the roles
right is fiddly. This visual builder assembles the array, validates the common
pitfalls, and exports a clean request body.
How it works
You add turns, pick a role for each from system, user, or assistant, and type
the content. As you edit, the builder validates live: it confirms there is at
least one user message and warns when a system message appears anywhere other
than first, since that is rarely intended. When the structure looks right, it
serialises a request body with a model field and the messages array, ready
to copy. Nothing is sent — you call the API yourself with your own key.
Example output
A three-turn conversation — one system prompt, one user question, one assistant reply — produces JSON like this:
{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a concise technical assistant. Answer in plain English without unnecessary preamble."
},
{
"role": "user",
"content": "What is the difference between a mutex and a semaphore?"
},
{
"role": "assistant",
"content": "A mutex is a lock owned by a single thread and released only by that thread. A semaphore is a counter that can be incremented and decremented by any thread, allowing a fixed number of concurrent accesses."
}
]
}
Paste this directly into a curl call or your SDK’s client.chat.completions.create() call, swapping the model name for whichever model your API key can access.
OpenAI vs Anthropic: the format difference
The two providers structure their inputs differently:
| Aspect | OpenAI | Anthropic |
|---|---|---|
| System prompt location | Inside messages as {"role":"system","content":"..."} | Separate top-level system field |
| Required roles | At least one user | First message must be user |
| Alternation requirement | Not strict | Strict — must alternate user/assistant |
| First role | system or user | user |
If you work with both providers, build each format separately and compare. The Anthropic Messages Builder is the companion tool for the Anthropic API format.
When to include prior assistant turns
Adding assistant turns to the messages array lets you prime the conversation: the model continues as if those previous exchanges actually happened. This is useful for:
- Few-shot prompting — show the model a worked example before asking your real question.
- Continuing a conversation — replay the history so the model has context for its next response.
- Steering the response format — include an assistant turn that begins the answer in the format you want, and the model tends to continue it.
The builder supports all three scenarios. Add as many turns as you need, then copy the complete array.
Tips and notes
- Lead with system. Put your instructions in a single system message at the top; the builder flags system messages placed later.
- Edit the model name. The exported body uses a placeholder model; change it
to whatever your key can access (
gpt-4o,gpt-4o-mini,o3, etc.). - Alternate for clarity. OpenAI tolerates non-alternating turns, but a clean user/assistant rhythm is easier to reason about and debug.
- Token costs scale with history. Every prior turn is re-sent on each API call. Keep few-shot examples short to avoid unnecessary cost.
- Pair with the Anthropic builder. If you support both providers, build each format side by side to keep your prompts in sync.