15Topic 15 of 15

Building with the API

Claude and OpenAI APIs: first request, tool use, structured output, caching, batch, streaming.

18 plates · 62 min to read them all


  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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.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
  16. 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
  17. 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
  18. 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

Other topics

All 105 plates →
  1. 01 Install & set up 5
  2. 02 First steps 4
  3. 03 Claude Code commands 9
  4. 04 Workflows 6
  5. 05 MCP 8
  6. 06 Claude 2
  7. 07 ChatGPT 6
  8. 08 Cursor 3
  9. 09 Local LLMs 12
  10. 10 Prompting 8
  11. 11 Choosing tools 5
  12. 12 AI images 7
  13. 13 Everyday tasks 7
  14. 14 Other coding agents 5

↑↓ move↵ openalt+↵ copy first command

Keyboard

⌘/ctrl+K or /
Search all guides
alt+↵
In search: copy the guide's first command
j / k
Move through a list of guides
c
On a guide: copy its first command
t
Toggle light / dark
?
This list