Claude & OpenAI API How-To Guides

Practical, current guides for building on the Claude and OpenAI APIs — streaming, tool use, function calling, prompt caching, and controlling spend.

Anthropic Message Batches API
How to use the Anthropic Message Batches API in Python — create batches, poll for results, retrieve…
Anthropic Prompt Caching
How to enable prompt caching on the Claude API with cache_control, when the 5-minute vs 1-hour TTL makes…
Anthropic Token Counting API
How to count tokens before sending to the Claude API — client.messages.count_tokens(), system prompt…
Claude API Streaming Python
How to stream Claude API responses in Python using the Anthropic SDK v0.34+. Covers sync and async…
How to Send Images to Claude API (Vision)
How to send images to the Claude API in Python — base64 encoding, URL sources, supported formats,…
Claude Tool Use API
How to use Claude tool use with the Anthropic Python SDK — tool definition, the 4-step call loop,…
How to Set a Hard Spend Limit on the OpenAI API (Avoid Surprise Bills, 2026)
The reliable way to cap OpenAI API spend: prepaid credits with auto-recharge off creates a true hard…
OpenAI API Streaming Python
How to stream OpenAI API responses in Python with the OpenAI SDK v1.x. Covers sync and async patterns,…
OpenAI Function Calling (Tools API)
How to use OpenAI function calling with the Python SDK v1.x — tool definition, the call loop,…
OpenAI Structured Outputs
How to use OpenAI structured outputs with the Python SDK — response_format json_schema, strict mode,…
OpenAI Token Counting with tiktoken
How to count tokens for OpenAI API requests using tiktoken in Python — get_encoding, encode, count…
OpenAI Whisper API
How to transcribe audio with the OpenAI Whisper API in Python — audio.transcriptions.create, file…
How to Reduce OpenAI API Costs
Cut your OpenAI API bill with 7 levers ranked by ROI: model selection, response caching, max_tokens…
OpenAI API Pricing (2026)
The GPT-5 per-token cost table: GPT-5.5, GPT-5.4, mini and nano, plus caching and Batch discounts. Verified against official sources.
Anthropic API Pricing (2026)
The Claude per-token cost table: Opus, Sonnet 4.6 and Haiku 4.5, the cheapest tier, and caching savings. Verified against official sources.