AI Advanced · 22% of the exam

Claude SDK & Anthropic APIs: free practice questions

5 sample questions from our 211-question bank for this domain — answers and explanations included. These are the same scenario-based style as the real DataCertPrep exam.

1. A team is evaluating whether to use the Anthropic Batch API or the standard synchronous Messages API for their use case. Which of the following scenarios is BEST suited for the Batch API? (Select TWO)

  • A. Running nightly classification of 200,000 support tickets where results are needed by the next business morning.✓ Correct
  • B. Powering a live chatbot where users expect responses within 2 seconds.
  • C. Generating marketing copy variants for 50,000 product SKUs as part of a weekly refresh job.✓ Correct
  • D. Streaming a code explanation to a developer in an interactive IDE plugin.
  • E. Re-ranking search results in real time based on a user's search query.
Explanation

The Batch API is designed for high-volume, latency-insensitive workloads where results can be collected asynchronously. Option A (200,000 tickets overnight) and Option C (50,000 product descriptions weekly) are both classic batch workloads—large volume, no real-time requirement, and significant cost savings (Batch API is typically 50% cheaper). Option B is wrong because a live chatbot with 2-second SLA requires synchronous, low-latency calls—the Batch API is asynchronous with processing times that can take minutes to hours. Option D is wrong because streaming to an IDE plugin is inherently interactive and real-time. Option E is wrong because real-time search re-ranking requires synchronous, sub-second responses.

2. Which of the following statements about the TTL (time-to-live) of prompt cache entries with `type: "ephemeral"` are correct? (Select TWO)

  • A. Cache entries have a fixed TTL of 5 minutes and are automatically evicted after that period of inactivity.
  • B. Cache entries persist for at least 5 minutes; each cache hit resets the TTL, keeping frequently accessed entries alive longer.✓ Correct
  • C. The TTL is indefinite for all paid tiers — cache entries are never evicted unless the developer explicitly deletes them.
  • D. Serving traffic from cache costs fewer input tokens than a full cache miss, making caching economically beneficial for repeated identical prefixes.✓ Correct
  • E. Cache entries are shared across different Anthropic API keys within the same organization, so a cache created by one developer benefits all teammates.
  • F. The `ephemeral` cache type is the only available cache type; there is no persistent or long-lived cache option in the current API.
Explanation

Options B and D are correct. B is correct: the `ephemeral` cache TTL is a minimum of 5 minutes, and cache hits refresh (extend) the TTL — so actively used cache entries remain valid longer. D is correct: reading from cache costs significantly fewer tokens than a full cache miss (cache reads are billed at a lower rate than standard input tokens), making prompt caching cost-effective for repeated prefixes like long system prompts. Option A is wrong because it states the TTL is 'fixed at 5 minutes' and implies no refreshing — the TTL resets on hits. Option C is wrong; cache entries do expire after inactivity and are not permanent. Option E is wrong; cache entries are scoped to the API key that created them and are not shared across keys even within the same organization. Option F is wrong; while `ephemeral` is the primary type, Anthropic's documentation references other cache behaviors and the landscape may evolve — more importantly, stating it as the only type is misleading.

3. An architect is designing a system where a Claude orchestrator spawns subagents using the Claude Code SDK. The orchestrator needs to delegate a file-writing task to a subagent but must restrict the subagent from executing arbitrary shell commands. Which approach correctly scopes subagent permissions in the Claude Code SDK?

  • A. Pass a `allowed_tools` list to the subagent configuration that includes file-writing tools (e.g., `write_file`) but excludes shell execution tools (e.g., `execute_bash`), preventing the subagent from invoking unauthorized tools.✓ Correct
  • B. Set `max_tokens: 256` on the subagent call to limit the number of actions the subagent can take before returning control.
  • C. Use `tool_choice: {"type": "none"}` on all subagent calls to disable tool use entirely and rely on text output only.
  • D. Wrap the subagent in a try/except block; the Claude Code SDK raises a `PermissionError` automatically when a subagent attempts to call a shell tool without explicit operator approval.
Explanation

Option A is correct: the Claude Code SDK supports scoping subagent capabilities by specifying an `allowed_tools` list. By explicitly listing only file-writing tools, the developer ensures the subagent cannot invoke shell execution or other unauthorized tools, implementing the principle of least privilege. Option B is incorrect: `max_tokens` controls output token length, not the number of tool calls or action steps; a subagent could still execute a shell command within a short response. Option C is incorrect: `tool_choice: {"type": "none"}` disables all tool use, which would prevent the file-writing task from being completed, not just shell execution. Option D is incorrect: the Claude Code SDK does not raise a `PermissionError` automatically based on tool type; permission scoping must be configured explicitly by the developer.

4. A developer is designing a tool-use system where Claude must ALWAYS use a specific tool called `log_interaction` on every turn, regardless of the user's request. Which `tool_choice` configuration achieves this?

  • A. {"type": "tool", "name": "log_interaction"}✓ Correct
  • B. {"type": "required"}
  • C. {"type": "auto"}
  • D. {"type": "any", "name": "log_interaction"}
Explanation

Setting `tool_choice` to `{"type": "tool", "name": "log_interaction"}` forces Claude to call exactly the named tool on every turn. This is the correct way to mandate use of a specific tool. Option B (`type: required`) forces Claude to use *some* tool but does not specify which one—Claude could choose any available tool. Option C (`type: auto`) is the default and allows Claude to decide whether and which tool to use, so it does not guarantee `log_interaction` is called. Option D uses a non-existent `"any"` type combined with `name`; `"any"` is not a valid `tool_choice` type in the Anthropic API.

5. An engineer is writing a tool definition for a Claude-powered application. The tool, `search_documents`, accepts two parameters: `query` (a required string) and `max_results` (an optional integer with a default of 10). Which JSON `input_schema` fragment correctly represents this specification?

  • A. `{"type": "object", "properties": {"query": {"type": "string"}, "max_results": {"type": "integer", "default": 10}}, "required": ["query"]}`✓ Correct
  • B. `{"type": "object", "properties": {"query": {"type": "string", "required": true}, "max_results": {"type": "integer", "default": 10, "required": false}}}`
  • C. `{"type": "object", "properties": {"query": {"type": "string"}, "max_results": {"type": "integer"}}, "required": ["query", "max_results"]}`
  • D. `{"type": "function", "parameters": {"query": {"type": "string"}, "max_results": {"type": "integer", "optional": true}}}`
Explanation

The Anthropic tool `input_schema` follows JSON Schema conventions. Required parameters are listed in a top-level `required` array, while optional parameters are simply absent from that array. Option A correctly places only `query` in `required` and omits `max_results` from it, while also including a `default` hint. Option B incorrectly embeds `required` as a per-property boolean attribute, which is not valid JSON Schema syntax used by the Anthropic API. Option C incorrectly lists both fields as required, which would force Claude to always provide `max_results`. Option D uses `"type": "function"` at the schema root and a `parameters` key—this is OpenAI function-calling format, not the Anthropic `input_schema` format.

206 more questions in this domain

Practice the full bank with instant grading, flashcards, and a timed mock exam.

Start practicing free