Migrating From GPT-4 to Claude: A Practical Porting Guide
Moving an application from OpenAI's API to Claude involves two kinds of work. Changing the API calls is quick. Checking that prompts still produce the behavior you need takes longer, and it's the part teams tend to underestimate.
Part 1: API differences
Most changes are mechanical:
- System prompt: passed as a top-level
systemparameter, not as a message with the rolesystem. max_tokens: required on every request.- Tools: the schema goes in
input_schemainstead ofparameters. Tool calls come back astool_usecontent blocks, and you return results astool_resultblocks in a user message rather than as messages with the roletool. - Responses:
contentis a list of blocks. Check each block'stypebefore reading text from it. - Stop reasons: named differently, for example
end_turn,max_tokens,tool_useandrefusal. - JSON output: use structured outputs or strict tool definitions instead of JSON mode.
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=4000,
system="You are a contracts assistant.",
messages=[{"role": "user", "content": question}],
)
answer = "".join(b.text for b in response.content if b.type == "text")
Use the official Anthropic SDK rather than a compatibility layer, so features like prompt caching and thinking work fully.
Part 2: Prompts
- Claude follows instructions closely. Prompts full of repeated warnings, written to control a different model, can make Claude too rigid. Remove the repetition.
- XML tags work well for separating instructions from documents.
- Explain why each rule exists. Claude applies rules more sensibly when it knows their purpose.
- Few-shot examples written for another model may need to be shortened or replaced.
Part 3: Evaluations
Compare the old and new versions before switching:
- Export a few hundred real requests along with outputs you know are correct.
- Run them through both setups.
- Compare task success, format compliance, refusals and cost.
- Read the differences yourself. Some will be improvements that your metrics don't capture.
Part 4: Rollout
Release behind a feature flag and send a small share of traffic to Claude first. Watch error rates and user feedback before moving everything over, and keep the old path available until the new one has handled a busy period.
Other differences to plan for
- The tokenizers differ, so token counts, costs and context estimates will change.
- Error types and retry behavior differ. Use the SDK's typed exceptions.
Budget a day for the code changes and most of the week for prompts and evaluations.