Skip to content
mentoor

Topic 4 of 5 · 5 min read

Comparing Claude, OpenAI and Gemini request shapes

Goal: Translate one request between the Claude, OpenAI and Gemini API shapes and name the differences that change behaviour.

The three big APIs do the same job with different field names, so learn the shared shape once and translate the differences instead of memorizing each vendor.

Check yourself · 1 of 3

In the Gemini generateContent API, which role name marks the model's earlier replies?

Choose one answer

Why it matters

Teams switch or add providers for price, quality, latency or data rules. If you know which parts are the same, a migration is a day of mapping, not a rewrite. If you do not, you copy a snippet from one vendor's docs into another's SDK and get errors, or worse, silent changes in behaviour.

The shared shape

Every call has a model, standing instructions, the conversation, an output limit and a response with text, a finish signal and usage. Only the names differ.

Idea Claude Messages OpenAI Responses Gemini generateContent
Standing rules system instructions systemInstruction
Conversation messages input contents
Assistant role name assistant assistant model
Output limit max_tokens (required) max_output_tokens generationConfig.maxOutputTokens
Answer text content[].text output_text candidates[0].content.parts[].text
Finish signal stop_reason status and incomplete_details finishReason

Differences that change behaviour

  • Required versus optional limits. Claude refuses a call without max_tokens. Others use a default, which may be larger or smaller than you want.
  • Role names. Gemini calls the model's turns model, not assistant. Sending the wrong name is an error.
  • Where the system text goes. In Claude it is not a message at all. Putting it into the list as a message will not work.
  • Auth. Claude takes an x-api-key header plus an anthropic-version header, which the SDK sets. The other two use their own key mechanisms.

Aliases versus pinned snapshots

A model name can be an alias that the vendor moves to a newer snapshot over time, or a pinned snapshot id that always means the same model. An alias gives you improvements without work, and also changes in tone, format and cost without warning. Pin a snapshot in production, test a newer one in staging, and move deliberately. Check the vendor's model page for which names are aliases.

Before and after

Weak: a Gemini call copied from a Claude example uses role: "assistant" and system in the list, and fails. Fixed: systemInstruction for the rules and role: "model" for earlier replies.

What goes wrong

  • Copy-paste across vendors with the wrong field names.
  • Relying on defaults for output limits and then getting different lengths on each provider.
  • Using an alias in production and seeing outputs shift after a model update.
  • Writing the app against one vendor's response object everywhere, which makes switching painful.

Examples

One request, three bodies

Claude:  {"model": M, "system": S, "max_tokens": 300, "messages": [{"role": "user", "content": Q}]}
OpenAI:  {"model": M, "instructions": S, "max_output_tokens": 300, "input": Q}
Gemini:  {"systemInstruction": {"parts": [{"text": S}]}, "generationConfig": {"maxOutputTokens": 300}, "contents": [{"role": "user", "parts": [{"text": Q}]}]}

Same content, three layouts. Gemini also puts the model in the URL path, not the body.

An alias moves

A team calls a model by its alias. After a vendor update the alias points to a newer snapshot, answers get longer, and a parser that expected a one-line label fails. Pinning the snapshot id in config would have kept the old behaviour until the team chose to test and switch.

Key points

  • All three APIs share the same parts: model, instructions, conversation, limit, text, finish signal, usage.
  • Field names differ: system, instructions and systemInstruction all hold standing rules.
  • Gemini names earlier model turns model, while Claude and OpenAI use assistant.
  • Claude requires max_tokens, while other providers fall back to their own defaults.
  • Pin a snapshot id in production because an alias can silently point to a newer model.

Common mistakes

  • Pasting one vendor's request body into another vendor's SDK and debugging the error messages.
  • Using role "assistant" in a Gemini request instead of "model".
  • Calling a model alias in production and being surprised when its behaviour changes.
  • Passing the system text as a message in the Claude Messages API.

Check yourself · 2 of 3

Which of these is the best reason to pin a snapshot model id instead of an alias in production?

Choose one answer

Check yourself · 3 of 3

You move a Claude call to the OpenAI Responses API. Which change is needed for the standing rules?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic