Convert OpenAI API request code into the Anthropic Messages API shape, with the differences that actually break migrations handled: system prompt placement, message roles, and parameter names.
Paste OpenAI SDK code. Get the Anthropic SDK equivalent with model mapping, parameter renames, and message-format adjustments.
from anthropic import Anthropic
client = Anthropic(api_key="sk-...")
response = client.messages.create(
system="You are a senior engineer.",model="claude-opus-4-7",
messages=[
{"role": "user", "content": "Refactor this function."},
],
max_tokens=1024,
temperature=0.2,
)
print(response.content[0].text)The migration detail that bites hardest is the system prompt. OpenAI takes it as a message with role system inside the messages array; Anthropic takes it as a top-level system parameter. Leaving it as a message does not throw an error. It just quietly stops behaving as a system prompt, which is a difficult bug to notice and an easy one to ship.
Response shape differs too. Anthropic returns content as an array of typed blocks rather than a single string, so code doing response.choices[0].message.content needs restructuring. Anthropic also requires max_tokens on every request, where OpenAI treats it as optional.