15Topic 15 of 15
Building with the API
Claude and OpenAI APIs: first request, tool use, structured output, caching, batch, streaming.
- 15.01 Your First Claude API Request: curl, Python, Node Get a key, set ANTHROPIC_API_KEY, and make a working Messages API call in curl, Python, and Node — then read the response properly. 3 min
- 15.02 Claude API Tool Use Define a tool with a JSON schema, catch the tool_use block, run your function, and send back a tool_result — in a minimal Python loop. 4 min
- 15.03 Get Reliable JSON Out of the Claude API Constrain replies with output_config.format, or use messages.parse with Pydantic and Zod, so the Claude API returns JSON that always validates. 3 min
- 15.04 Prompt Caching in the Claude API with cache_control Cache a long system prompt or document with cache_control, confirm hits in the usage fields, and know when the 1.25x write cost pays for itself. 3 min
- 15.05 Claude Message Batches API: Bulk Jobs at Half Price Create a batch of Messages requests, poll processing_status, stream results by custom_id — and pay 50% less than synchronous calls. 3 min
- 15.06 Your First OpenAI API Request (Responses API) Create a key, set OPENAI_API_KEY, and make a working Responses API call in curl, Python, and Node — the API OpenAI recommends for new projects. 3 min
- 15.07 OpenAI Structured Outputs: JSON Schema Constrain Responses API output with text.format json_schema, parse straight into Pydantic or Zod, and use the same strict schemas for function calling. 4 min
- 15.08 Stream LLM Responses: Claude and OpenAI Print tokens as they arrive from the Claude and OpenAI APIs — Python and JavaScript, plus the raw SSE events and how to detect the end. 4 min
- 15.09 Claude Agent SDK for Python: Your First Agent Install claude-agent-sdk, run an agent that reads and edits real files, control which tools it may use, and read the final result. 4 min
- 15.10 Claude Agent SDK for TypeScript: Your First Agent Install @anthropic-ai/claude-agent-sdk, stream an agent that edits real files, gate its tools, and read the final result message. 4 min
- 15.11 Send a PDF to the Claude API (With Page Citations) The document content block in Python, the page and size limits from the docs, citations that point at a page — and when to pre-extract text instead. 4 min
- 15.12 Claude API Thinking and Effort Turn adaptive thinking on, read the thinking blocks, dial depth with output_config.effort (low → max), stream deltas, and know what budget_tokens means. 4 min
- 15.13 Send an Image to the Claude API (base64, URL, Files) The image content block in Python and curl, the format and size limits from the docs, and a screenshot-to-CSV extraction that doesn't invent numbers. 4 min
- 15.14 Embeddings Explained, With Code What an embedding vector actually is, how to compute two and compare them in Python, and which model and dimension to pick. 3 min
- 15.15 Your First Gemini API Request Get a Gemini API key from AI Studio, set GEMINI_API_KEY, install the google-genai SDK, and make a working request with the Interactions API. Copy-paste. 2 min
- 15.16 Generate Images with the OpenAI API (gpt-image) Two ways to make an image with the OpenAI API — the Images endpoint and the image_generation tool — save the PNG, set size, quality and format. 3 min
- 15.17 RAG Without a Vector Database: OpenAI File Search Upload files to an OpenAI vector store, attach the file_search tool to a Responses API call, and get cited answers — no embeddings code, no database. 3 min
- 15.18 A Minimal RAG in Python: Folder In, Cited Answer Out Chunk a folder of Markdown, embed it with Voyage, retrieve top-k with a numpy dot product, and answer with Claude citing the chunks it used. 4 min
Keep going