Lesson

Understanding API Parameters (Model, Tokens, Temp)

When you make a request to the Anthropic API, the messages array contains your actual prompt. But the other parameters control how Claude thinks and behaves.

Let's look at the three most important parameters: model, max_tokens, and temperature.

1. Model Selection

Anthropic provides a family of Claude models, usually branded as Opus, Sonnet, and Haiku. In the API, you specify the exact version string (e.g., claude-3-sonnet-20240229).

  • Haiku (claude-3-haiku-20240307): The fastest and cheapest model. Use this for simple tasks, quick classification, or when you are processing thousands of documents and need to keep costs down.
  • Sonnet (claude-3-sonnet-20240229): The middle ground. It's incredibly smart (great for coding) but still very fast and moderately priced. This should be your default choice for most web apps.
  • Opus (claude-3-opus-20240229): The heavy lifter. It is the most expensive and the slowest, but it possesses the highest reasoning capabilities. Use this for complex logic, math, or deep architectural design.

Note: Model versions update over time. Always check the Anthropic documentation for the latest version strings.

2. Max Tokens (max_tokens)

A token is roughly equivalent to a word (or a piece of a word).

When you set max_tokens: 1000, you are telling the API, "If Claude tries to generate more than 1000 tokens, cut it off immediately."

This is a required safety feature. If you ask Claude to write an infinite loop in Python, and it gets stuck repeating the same code, max_tokens ensures you don't get a $5,000 API bill.

Pro-Tip: If you are asking for a long essay and the response cuts off abruptly mid-sentence, you probably hit your max_tokens limit. Increase the number.

3. Temperature (temperature)

Temperature controls the "creativity" or randomness of the response. It takes a decimal value between 0.0 and 1.0.

  • Temperature 0.0: Claude becomes highly deterministic. If you ask the exact same question 5 times, you will get the exact same answer 5 times. It chooses the most statistically likely next word. Use this for code generation, data extraction, and rigid logic.
  • Temperature 1.0: Claude becomes highly creative. It takes more risks with vocabulary and structure. Use this for brainstorming, writing marketing copy, or generating ideas.

By default, the API usually sets temperature to 1.0 if you don't specify it. If you are building a tool that extracts JSON data from emails, you should explicitly set temperature: 0.0 to prevent Claude from getting "creative" with your JSON schema.

Ready to test your understanding? Take the quiz to reinforce what you learned.

© 2026 Ant Skillsv.26.07.07-23:01