Claude API
How do you pass a system prompt in the Claude API?
QUICK ANSWER
Pass a system prompt by declaring the top-level 'system' string parameter in your API body request payload. Do not mix system instructions into the 'messages' array role declarations.
JSON Payload Configuration
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"system": "You are a specialized code translator. Output only clean code.",
"messages": [
{"role": "user", "content": "Translate x = 1 to JavaScript."}
]
}
Verified against: Anthropic API v1