AI Advanced · 22% practice allocation

AI Advanced: Claude SDK & Anthropic APIs Practice Questions

5 free sample questions from the Claude SDK & Anthropic APIs domain, with answers and explanations. The full AI Advanced bank has 794 questions across 5 domains. Questions follow the AI Advanced course content.

1.

A developer wants to reduce API costs for a customer support chatbot. The system prompt is 2,000 tokens and is identical across all conversations. They add cache_control: {"type": "ephemeral"} to the system prompt. Regarding prompt caching behavior, which TWO statements are accurate?

Select TWO.

  • A. The cache entry has a 5-minute TTL and is refreshed on every cache hit.
  • B. A cache hit on the system prompt is billed at a lower per-token rate than a cache miss.✓ Correct
  • C. Prompt caching is only available on Claude Haiku models.
  • D. The minimum cacheable token block size is 1,024 tokens for Claude 3 models.✓ Correct
  • E. Each unique combination of model version and API key shares the same cache namespace.
  • F. Cached tokens count toward the model's context window but not toward output token billing.
Explanation

Statement B is correct: cache hits are charged at a significantly reduced input token rate (roughly 10% of the standard input price), making repeated identical prefixes much cheaper. Statement D is correct: the minimum cacheable prefix for Claude 3 models is 1,024 tokens; shorter blocks will not be cached. — Statement A is wrong on the TTL: the ephemeral cache TTL is 5 minutes, but it is reset (extended) on each cache hit, not simply refreshed — however more importantly, the 5-minute TTL detail itself is accurate but 'refreshed on every cache hit' overstates the behavior; the TTL resets to 5 minutes from the last hit, which is a nuanced but relevant distinction making this option partially misleading and not a clean 'accurate' statement compared to B and D. Statement C is wrong: prompt caching is available across multiple Claude 3 model tiers, not only Haiku. Statement E is wrong: caches are scoped per API key and model, but different API keys do NOT share a cache namespace. Statement F conflates input caching with output billing; cached tokens still count toward context window limits but the statement about output token billing is a non-sequitur — output tokens are priced separately regardless.

2.

A developer wants to build a multi-turn conversation where Claude can call tools. After Claude returns a tool_use block, the developer correctly calls the tool and now needs to append the result before making the next API call. What is the correct structure of the messages array for the follow-up request?

  • A. Append a single message with role: "tool" and content containing the tool result string
  • B. Append a new user message containing a tool_result content block; there is no need to re-include the previous assistant message since it is already in the conversation history
  • C. Append the original assistant message containing the tool_use block, then append a new user message containing a tool_result content block with the matching tool_use_id✓ Correct
  • D. Append a new assistant message with role: "assistant" and a tool_result content block containing the output
Explanation

Option C is correct: the Anthropic API requires the full conversation history in each request. After Claude returns an assistant message containing a tool_use block, you must include that assistant message in the history and then add a new user message whose content is a tool_result block that references the tool_use_id from the assistant's tool call. Option A is incorrect; there is no "tool" role in the Anthropic API — tool results are submitted as user role messages with a tool_result content block type. Option B is incorrect about the need to re-include the assistant message: the Anthropic API is stateless, and all prior messages (including the assistant's tool_use message) must be sent with every request. Option D is incorrect; tool_result blocks belong in a user role message, not an assistant role message.

3.

A developer wants to use the Anthropic Python SDK to stream a response and print each text delta to the console as it arrives. Which streaming approach correctly uses the SDK's recommended streaming interface?

  • A. response = client.messages.create(model=MODEL, max_tokens=1024, messages=messages, stream=True) for chunk in response: print(chunk.delta.text, end="", flush=True)
  • B. with client.messages.stream(model=MODEL, max_tokens=1024, messages=messages) as stream: for text in stream.text_stream: print(text, end="", flush=True)✓ Correct
  • C. stream = client.messages.stream_create(model=MODEL, max_tokens=1024, messages=messages) while not stream.done(): print(stream.next_chunk())
  • D. async for event in client.messages.create_stream(model=MODEL, max_tokens=1024, messages=messages): if event.type == "text": print(event.text)
Explanation

Option B is correct: the Anthropic Python SDK provides a client.messages.stream() context manager that yields a stream object; iterating over stream.text_stream yields successive text delta strings, which is the idiomatic high-level streaming API. Option A is incorrect because stream=True is the OpenAI SDK pattern; the Anthropic SDK uses client.messages.stream() as a context manager, not a stream=True flag on messages.create. Option D is incorrect because create_stream is not a method in the Anthropic SDK; it is a fabricated name. Option C is incorrect because stream_create and stream.done() / stream.next_chunk() are not part of the Anthropic SDK's interface.

4.

A developer is configuring the Claude Desktop application to connect to a custom MCP server they wrote. The server is a Node.js script located at /usr/local/bin/my-mcp-server.js. Which of the following Claude Desktop configuration entries correctly registers this MCP server?

  • A. {"mcpServers": {"my-server": {"command": "node", "args": ["/usr/local/bin/my-mcp-server.js"]}}}✓ Correct
  • B. {"mcpServers": {"my-server": {"script": "/usr/local/bin/my-mcp-server.js", "runtime": "node"}}}
  • C. {"tools": [{"name": "my-server", "executable": "node /usr/local/bin/my-mcp-server.js"}]}
  • D. {"mcpServers": {"my-server": {"url": "http://localhost:3000", "transport": "http"}}}
Explanation

Claude Desktop's MCP configuration uses a mcpServers object where each entry specifies a command (the executable) and args (an array of arguments). For a Node.js script, command should be "node" and args should contain the script path. Option D describes an HTTP-based transport format; while some MCP transports use HTTP, Claude Desktop's stdio-based local server config requires command/args, not a URL. Option C uses a tools array with an executable key—this schema does not match Claude Desktop's MCP configuration format at all. Option B uses script and runtime keys, which are not valid fields in the Claude Desktop MCP server configuration spec.

5.

A developer wants to enable prompt caching on a specific content block within the messages array (not the system prompt). Which of the following correctly applies a cache breakpoint to the last user message's content?

  • A. messages=[ {"role": "user", "content": [ {"type": "text", "text": "Analyze this document: ..."}, {"type": "cache_marker", "cache_control": {"type": "ephemeral"}} ]} ]
  • B. messages=[ {"role": "user", "content": [ {"type": "text", "text": "Analyze this document: ...", "cache_control": {"type": "ephemeral"}} ]} ]✓ Correct
  • C. messages=[ {"role": "user", "content": [ {"type": "text", "text": "Analyze this document: ...", "cache": true} ]} ]
  • D. messages=[ {"role": "user", "content": "Analyze this document: ...", "cache_control": {"type": "ephemeral"}} ]
Explanation

Option B is correct: cache_control is placed directly inside an individual content block object (when content is an array of block objects), not at the message level. The breakpoint is a property of the specific content block where the cache boundary should be set. Option D is wrong because placing cache_control at the message level (alongside role and content) is not the correct structure; it must be inside a content block object when content is structured as an array. Option A is wrong because there is no cache_marker content block type in the Anthropic API; cache_control is added directly to existing content block types like text or image. Option C is wrong because cache: true is not a valid field; the correct field name and structure is cache_control: {"type": "ephemeral"}.

Test yourself across every AI Advanced domain

The free AI Advanced practice test mixes about 20 questions weighted like the exam. The full 794-question bank adds instant grading, flashcards and a timed mock exam.

Study this domain

Claude SDK & Anthropic APIs study guide (AI Advanced) →

Other AI Advanced domains

← All AI Advanced study resources