Claude API Request Parameters Cheatsheet
A dense reference for the parameters you'll pass to client.messages.create(...) on nearly every call, plus the ones you'll reach for less often.
Use it to look up a parameter's type, default, and when to adjust it, without digging through prose docs.
How to Use This Cheatsheet
- Start with
modelandmax_tokens, the only two required parameters. - Adjust
temperatureortop_pwhen output feels too repetitive or too erratic, but usually only one of the two. - Treat
top_kas a rarely-needed, more aggressive sibling oftop_p. - Revisit this table whenever you're tuning a new use case's determinism or output length.
Core Parameters
| Parameter | Type | Required? | Default | Description |
|---|---|---|---|---|
model | string | Yes | none | The model ID to use, e.g. claude-sonnet-5-20260630. Exact ID strings change over time - verify current values in the docs before hardcoding. |
max_tokens | integer | Yes | none | Hard ceiling on tokens Claude may generate in the response. Generation stops immediately when reached, even mid-sentence. |
messages | array | Yes | none | Ordered list of `{"role": "user" |
system | string | No | none | Persistent instructions applied across the whole conversation, set outside the messages array. |
temperature | number | No | 1.0 | Controls randomness, 0 is near-deterministic, higher values are more varied. Range 0 to 1. |
top_p | number | No | 1.0 | Nucleus sampling - restricts token choice to the smallest set whose cumulative probability reaches top_p. |
top_k | integer | No | none (unset) | Restricts token choice to the k most likely next tokens. Coarser and less commonly used than top_p. |
stream | boolean | No | false | When true, the response is returned as a sequence of server-sent events instead of one JSON object. |
stop_sequences | array of string | No | none | Custom strings that, if generated, stop the response early. |
Model ID Reference
| Model | Illustrative ID pattern | Tier |
|---|---|---|
| Claude Fable 5 | claude-fable-5-20260615 | Top / Mythos-class, 1M context, 128K max output |
| Claude Opus 4.8 | claude-opus-4-8-20260415 | Flagship reasoning, 1M context by default |
| Claude Sonnet 5 | claude-sonnet-5-20260630 | Default model, released 2026-06-30 |
| Claude Haiku 4.5 | claude-haiku-4-5-20260601 | Fastest / cheapest, 200K context |
Model ID strings shown here follow the current naming pattern (claude-<name>-<version>-<date>) but should be verified against the live docs before use, exact strings and availability change as new versions ship.
temperature vs. top_p vs. top_k
| Parameter | What It Controls | Typical Range to Adjust | Combine With |
|---|---|---|---|
temperature | Overall randomness of token selection | 0.0-0.3 for factual/structured tasks, 0.7-1.0 for creative tasks | Usually adjusted alone |
top_p | Nucleus size, how much of the probability mass is eligible | 0.9-1.0 for most tasks | Often left at default while tuning temperature |
top_k | Hard cutoff on candidate token count | Rarely changed from unset; 40-100 if used | Rarely combined with aggressive temperature changes |
Usage Examples
import anthropic
client = anthropic.Anthropic()
# Deterministic, factual task: low temperature
factual = client.messages.create(
model="claude-sonnet-5-20260630",
max_tokens=100,
temperature=0.0,
messages=[{"role": "user", "content": "What is the boiling point of water at sea level?"}],
)
# Creative brainstorming: higher temperature
creative = client.messages.create(
model="claude-sonnet-5-20260630",
max_tokens=300,
temperature=0.9,
messages=[{"role": "user", "content": "Brainstorm five taglines for a coffee shop."}],
)
# Streaming a longer response
with client.messages.stream(
model="claude-opus-4-8-20260415",
max_tokens=1000,
messages=[{"role": "user", "content": "Write a short story about a lighthouse."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)Frequently Paired Parameters
| Parameter | Type | Pairs Well With | Why |
|---|---|---|---|
system | string | temperature | A focused system prompt plus low temperature gives consistent, on-task output. |
stream | boolean | max_tokens | Streaming with a generous max_tokens suits long-form generation shown incrementally. |
stop_sequences | array | max_tokens | Combine a hard token cap with a semantic stop point for structured formats like JSON. |
FAQs
Which parameters are required on every call?
model, max_tokens, and messages. Everything else is optional and has a documented default.
What happens if I don't set temperature?
It defaults to 1.0, the most varied setting; for tasks needing consistent, repeatable output, set it lower explicitly.
Should I adjust both temperature and top_p at the same time?
Generally no. Pick one to tune for a given task, adjusting both aggressively at once makes behavior harder to predict and debug.
What's the difference between top_p and top_k?
top_prestricts the candidate pool by cumulative probability (a soft, adaptive cutoff).top_krestricts it to a fixed number of top candidates (a hard, static cutoff).
Does max_tokens control how long the response will be?
It sets an upper limit, not a target; Claude may stop naturally well before reaching it, or get cut off if it hits the ceiling mid-response.
Where do system prompts go in the request?
In a top-level system parameter, separate from the messages array, not as a message with a "system" role.
Are the model ID strings shown here guaranteed to be correct?
No, they illustrate the current naming pattern as of ~June 2026 but exact strings and available dates change; always verify against the live API docs before hardcoding a model ID in production.
What does stop_sequences do that max_tokens doesn't?
max_tokens is a hard length ceiling regardless of content; stop_sequences stops generation as soon as a specific string appears, useful for structured output formats.
Is stream a required parameter?
No, it defaults to false; set it to true only when you want incrementally delivered output instead of one final JSON response.
Which parameter should I lower first if output feels too random?
temperature, it's the most direct and commonly used control; only reach for top_p or top_k if lowering temperature alone doesn't get the behavior you want.
Related
- Understanding the Claude API Request Lifecycle - where these parameters fit in a request.
- Claude API Fundamentals Basics - these parameters used in runnable examples.
- Selecting a Model: Claude Fable 5, Opus 4.8, Sonnet 5, and Haiku 4.5 - choosing the right
modelvalue.
Stack versions: Written against the Claude model lineup current as of ~June 2026 - Claude Fable 5, Claude Opus 4.8, Claude Sonnet 5 (the default), and Claude Haiku 4.5 - and the official
anthropicPython SDK (latest 0.x release). Model names, SDK versions, and pricing move quickly - verify current specifics at platform.claude.com/docs before relying on them.