15Topic 15 of 16
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 it straight into Pydantic or Zod, and reuse 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 on adaptive thinking, read thinking blocks, set depth with output_config.effort (low to max), stream deltas, and know what budget_tokens does. 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. 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
- 15.19 Upload and reuse files with the Claude Files API Upload a PDF once with the Claude Files API, reference it by file_id across requests in Python, then list and delete it. 3 min
- 15.20 Count tokens and estimate API cost before you send Count tokens locally with tiktoken or Anthropic's count_tokens endpoint, then estimate cost from each provider's published per-token prices. 3 min
- 15.21 Use Gemini API File Search (managed RAG) Create a managed File Search store with the google-genai SDK, import a file, query it with the file_search tool, and read citations. 3 min
- 15.22 Get structured JSON output from the Gemini API Make the Gemini API return JSON that matches a Pydantic schema with the google-genai SDK, then parse it into a typed object. 3 min
- 15.23 Call functions (tools) with the OpenAI API Give the model your own functions with the OpenAI Responses API: define a tool, run the call it returns, and send the result back in a loop. 3 min
Keep going