Skip to content
Claude Certified Developer – Foundations (CCDV-F) Exam Prep

Lesson 3 of 25 · 9 min

x
3/25

Claude API Mechanics

Video lesson: CCDV-F 03/25: Claude API Mechanics (Domain 2, 6.8%)

Official scope (Exam Guide v1.0): Messages, tools, streaming, vision, thinking, caching, invoking Claude through third-party vendors, data access patterns, batch, and realtime vs batch trade-offs. The most concrete Domain 2 skill.

Request

FieldNotes
modelA model ID. Every ID is a pinned snapshot, including dateless IDs from the 4.6 generation on
max_tokensRequired. A ceiling, not a target. Thinking counts inside it
messagesFull history every call; the API is stateless
systemTop-level field, not a message role
tools, tool_choice, stream, thinking, output_configOptional

Response and stop reasons

content is an array of blocks (text, tool_use, thinking, ...). Read by type. usage reports tokens. Check stop_reason before using the answer.

stop_reasonMeaningAction
end_turnFinishedUse it
max_tokensHit your limit; truncatedRaise the limit or continue; incomplete tool_use means retry higher
stop_sequenceYour stop sequence firedRead stop_sequence
tool_useWants a client toolRun it; return a tool_result for every tool_use block
pause_turnA server-tool loop hit its iteration limit (default 10)Send the assistant content back unchanged to continue
refusalDeclined; a normal HTTP 200Read stop_details; retry on a fallback model
model_context_window_exceededFilled the context windowTreat as truncated

A loop must handle any stop reason. Empty end_turn replies are usually caused by adding text after tool_result blocks: send tool_result blocks alone.

Tool-use loop

tool_use block (id, name, input) → your code runs it → user message with tool_result and matching tool_use_id → repeat while stop_reason is tool_use. Claude may request several tools at once; return all results together.

Streaming

stream: true returns server-sent events: message_start → per block content_block_start, deltas, content_block_stop → message_delta (carries stop_reason) → message_stop. Tool inputs arrive as partial JSON: parse at block stop. An error can arrive after a 200 has started; handle mid-stream error events separately.

Prompt caching

  • Caches a prefix in order tools → system → messages. Up to 4 breakpoints; automatic caching (one top-level cache_control) moves a breakpoint forward as the conversation grows. Lookback window: 20 blocks.
  • Minimum cacheable length: 512 tokens on the current 5.x models (1,024 to 4,096 on older ones). Below it, nothing is cached and no error is returned.
  • TTL 5 minutes (write 1.25x base input) or 1 hour (write 2x). Reads 0.1x base input by default (lower on some newest models).
  • Changing tool definitions invalidates everything; tool_choice or images invalidate messages; thinking or effort changes invalidate messages; switching fast/standard speed invalidates system and messages.
  • Proof: cache_creation_input_tokens, cache_read_input_tokens, input_tokens (total input is the sum of all three).

Batch

Message Batches API: 50% off, up to 100,000 requests or 256 MB per batch, most finish within 1 hour, expire if not done in 24 hours, results kept 29 days. Results can come back in any order: match on custom_id. Result types: succeeded, errored, canceled, expired (the last three are not billed).

Vision

  • Image blocks by base64, URL or Files API file_id. On Amazon Bedrock and Google Cloud only base64 is available.
  • JPEG, PNG, GIF (first frame), WebP. Up to 600 images per API request (100 for 200k-context models); 10 MB per image on the API (5 MB on Bedrock and Google Cloud); 32 MB request limit often hits first.
  • Cost: 28x28-pixel patches, ceil(w/28) x ceil(h/28) tokens; oversized images are downscaled. Images before the question works best.
  • Limits: will not identify people; approximate counting and coordinates; small (<200 px) or rotated images are error-prone; cannot generate images.

Thinking (verified, summary; detail in 5.2)

Thinking tokens are billed as output and count inside max_tokens. Adaptive thinking plus effort on current models; manual budget_tokens only on older ones. Return thinking blocks unmodified during tool use.

Third-party platforms

  • Claude runs on the Claude API, Claude Platform on AWS, Microsoft Foundry (Anthropic-operated) and Amazon Bedrock, Google Cloud (partner-operated).
  • Model IDs differ: Bedrock uses anthropic.claude-opus-5-5; the others use the Claude API ID.
  • Partner-operated platforms set their own lifecycle dates; feature availability differs. Example: the current Bedrock endpoint lacks Agent Skills, the MCP connector, structured outputs, Files API inputs and server tools; fast mode is first-party (and Foundry on Azure) only.

Data access patterns

Stateless API: resend history. Files API uploads once and references by file_id (500 MB per file, 1 TB per org; files are workspace-scoped, so never accept file_ids from end users). Large documents and many images hit request-size limits first.

Realtime vs batch (design guidance, matches the guide's sample question)

Someone waiting: realtime (stream it). Nobody waiting and cost matters: batch.

Exam traps

  • max_tokens optional (it is required) or treated as a target length.
  • system as a message role.
  • A 200 means success (check stop_reason; refusal is also a 200).
  • Caching a 40-token prompt and expecting savings.
  • Matching batch results by position instead of custom_id.
  • Expecting URL images on Bedrock or identical model IDs on every platform.

References

  1. Handling stop reasons — checked Oct 16, 2026
  2. Errors — checked Oct 16, 2026
  3. Prompt caching — checked Oct 16, 2026
  4. Batch processing — checked Oct 16, 2026
  5. Vision — checked Oct 16, 2026
  6. Files API — checked Oct 16, 2026
  7. Models overview — checked Oct 16, 2026
  8. Claude in Amazon Bedrock — checked Oct 16, 2026

Check your understanding

  • Answer cut off mid-sentence, HTTP 200. What should the code have checked?Show answer

    Answer

    stop_reason (max_tokens).
  • Your cache counters are both zero. Most likely cause?Show answer

    Answer

    Prefix below the minimum cacheable length.
  • Overnight job, 50k prompts. Interface and how to match results?Show answer

    Answer

    Message Batches API; custom_id.
  • The same app moves from the Claude API to Bedrock and breaks. Two things to check?Show answer

    Answer

    Model ID format and feature availability (for example URL images, Files API, beta features).
Previous

Progress is saved in this browser.

Next Lesson