Français

🔬 Claude API: Deep Dive

Applied AI — Advanced Level · Session 1 · Yann Isola

CLAUDE CERTIFIED ARCHITECT PREPARATION

API Request Builder

Assemble a query POST /v1/messages complete. The JSON (JavaScript Object Notation) updates live, along with a simulated response illustrating the stop_reason expected. ⚠ Model names and prices volatile — check docs.anthropic.com.

1024
0.2
Prefilling — add a turn assistant partial "{" (forces JSON)
cache_control — set a cache breakpoint on the system prompt (−90% reading )
stream:true — SSE flow response (Server-Sent Events)
JSON query


      
Simulated response


      
Curl equivalent

  

SSE Streaming Viewer

SSE = Server-Sent Events: unidirectional HTTP flow text/event-stream . Run the simulation and watch each event happen — this is exactly the sequence your code should parse. Certification trick question: in what event happens stop_reason final?

SSE Event Log
Reconstructed text (concatenation of text_delta)
— waiting for the flow —
TTFT (Time To First Token)
0
events received
0
exit tokens
stop_reason (via message_delta)
The canonical sequence: message_start → content_block_start → content_block_delta× n → content_block_stop → message_delta → message_stop . THE ping interspersed are keep-alives to be ignored.

Token counter & cost calculator

Paste a text: estimation of the number of tokens (local heuristic — in production, use the endpoint count_tokens of the API, each family of models having its own tokenizer) and calculation of the cost per model. ⚠ Indicative and volatile prices.

Prompt caching (stable prefix)
API batches (−50 % )
0
characters
0
words
0
estimated tokens (input)
0 %
window 200k ⚠
Model ⚠Entry $/Mtok ⚠Output $/Mtok ⚠Cost/callCost / dayCost / month (30 days)
Heuristic: ~3.8 characters/token on average (French tokenizes a little denser than English; code and JSON vary). Alone count_tokens is authentic for the model actually called.