Why OpenAI, Anthropic, Gemini, and Ollama Prompt Formats Differ
OpenAI, Anthropic, Gemini, and Ollama all use conversational message formats for their APIs, but the structures are different enough that a prompt formatted for one provider won't work directly with another. The differences are intentional — each provider made independent decisions about how to structure multi-turn conversations, system instructions, and role names.
OpenAI format
OpenAI's chat completions API uses a flat messages array where system, user, and assistant messages are all peers:
{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is JSON?"},
{"role": "assistant", "content": "JSON is a text format..."},
{"role": "user", "content": "Give me an example."}
]
}
Anthropic format
Anthropic separates the system prompt from the conversation history — the system prompt is a top-level parameter, not a message:
{
"model": "claude-3-5-sonnet-20241022",
"system": "You are a helpful assistant.",
"messages": [
{"role": "user", "content": "What is JSON?"},
{"role": "assistant", "content": "JSON is a text format..."},
{"role": "user", "content": "Give me an example."}
]
}
Gemini format
Gemini uses a contents array instead of messages, wraps content in a parts array, uses model instead of assistant for the AI role, and separates the system instruction as a dedicated top-level field:
{
"system_instruction": {"parts": [{"text": "You are a helpful assistant."}]},
"contents": [
{"role": "user", "parts": [{"text": "What is JSON?"}]},
{"role": "model", "parts": [{"text": "JSON is a text format..."}]},
{"role": "user", "parts": [{"text": "Give me an example."}]}
]
}
Ollama format
Ollama's API is designed to be OpenAI-compatible — the structure is similar to OpenAI's, with messages array and the same role names. The main difference is the model field references a local model name rather than an OpenAI model identifier:
{"model": "llama3.2", "messages": [...]}
System prompt support varies by model. Llama 3 handles system messages in the messages array well. Some older models work better with the system prompt embedded in the first user message using the model's instruction format.