Claude SDK & Anthropic APIs Study Guide — AI Advanced

22% of the exam · domain 2 of 5 · AI Advanced · Free Claude SDK & Anthropic APIs practice questions

0 of 50 topics covered
What the exam asks here — tap to tick off0 / 10 covered
Domain 2 of 5

Claude SDK & Anthropic APIs

This domain covers 22% of the AI-ADV exam and tests your ability to build production-grade applications using Anthropic's Python and TypeScript SDKs, advanced API features, and integration patterns. Questions probe exact parameter names, default values, behavioral limits, and architectural decisions — not just conceptual understanding. Expect scenario-based questions that require you to distinguish between similar features and identify correct implementation patterns.


Anthropic Python/TypeScript SDK: Client Setup, Messages.create, Streaming

Client Setup

The Anthropic SDK is available for Python (anthropic) and TypeScript/Node.js (@anthropic-ai/sdk). Authentication uses the ANTHROPIC_API_KEY environment variable by default, or you pass it explicitly to the client constructor.

import anthropic
client = anthropic.Anthropic(api_key="sk-ant-...")  # or reads from env
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });

messages.create Parameters

ParameterTypeRequiredNotes
modelstringYese.g. claude-opus-4-5, claude-sonnet-4-5
max_tokensintegerYesUpper bound on output tokens
messagesarrayYesList of {role, content} objects
systemstring or arrayNoSystem prompt; array form enables cache_control
temperaturefloatNoDefault 1.0; range 0.0–1.0
streambooleanNoDefault false
toolsarrayNoTool definitions for function calling
tool_choiceobjectNoControls tool selection behavior

Streaming

Streaming returns server-sent events. Use the .stream() helper for managed streaming or pass stream=True to messages.create.

with client.messages.stream(model="claude-opus-4-5", max_tokens=1024, messages=[...]) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
    message = stream.get_final_message()

Common traps:

  • Forgetting max_tokens is required — omitting it raises a validation error.
  • Assuming temperature default is 0 — it is 1.0.
  • Confusing .stream() helper (managed, has get_final_message()) with raw messages.create(stream=True) (returns an iterator of raw events).
  • stop_reason values: end_turn, max_tokens, stop_sequence, tool_use — not "finish" or "stop".

Tool Use (Function Calling): Tool Definitions, input_schema, tool_result Blocks

Tool Definition Structure

Each tool is a JSON object with three required fields:

{
  "name": "get_weather",
  "description": "Get current weather for a city",
  "input_schema": {
    "type": "object",
    "properties": {
      "city": {"type": "string", "description": "City name"},
      "units": {"type": "string", "enum": ["celsius", "fahrenheit"]}
    },
    "required": ["city"]
  }
}

Tool Use Flow

Bold caption: Tool use request-response cycle showing message roles and content block types.

Content Block Types

Block TypeRolePurpose
textassistantRegular text output
tool_useassistantModel requests a tool call; has id, name, input
tool_resultuserApplication returns result; has tool_use_id, content
thinkingassistantExtended thinking output (read-only)

tool_choice Options

ValueBehavior
{"type": "auto"}Model decides whether to use tools (default)
{"type": "any"}Model must use at least one tool
{"type": "tool", "name": "X"}Model must use the specific tool X

Common traps:

  • tool_result blocks go in a user role message, not assistant.
  • The tool_use_id in tool_result must exactly match the id from the tool_use block.
  • input_schema must be valid JSON Schema — missing "type": "object" at root is a common error.
  • Setting tool_choice to {"type": "any"} does not guarantee a specific tool — use "tool" type for that.
  • Tool results with errors: set "is_error": true in the tool_result block rather than omitting it.

Worked scenario: You need Claude to always call your search_database tool before answering. Use tool_choice: {"type": "tool", "name": "search_database"}. Using "any" would allow Claude to call any tool in your list.


Unlock with a paid plan

11 more sections (about 2,125 words) continue below. Every paid plan unlocks all AI Advanced study guides, the full question bank and mock exams, from $4.97/month.