Skip to content

About

Copy-paste Claude (Anthropic) API recipes in Python — structured output, tool use, caching, batching

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

LLM Automation Cookbook — copy-paste Claude (Anthropic) recipes in Python

tests python license

Short, self-contained, copy-paste recipes for automating real work with the Claude (Anthropic) API in Python. Every recipe is one file you can drop into your project — structured output, tool use, streaming, prompt caching, batching, retries, vision, and more. All recipes are linted in CI to use current models and avoid deprecated parameters.

Each file is standalone. Copy the one you need, set ANTHROPIC_API_KEY, run it.

Recipes

# Recipe What it shows
01 Call the Claude API in Python The minimal request/response
02 Use a system prompt Steer tone and format
03 Extract structured JSON with Pydantic messages.parse → typed object
04 Tool use / function calling loop The agentic tool-use loop
05 Stream a response Token-by-token output
06 Adaptive thinking + effort Opus 4.8 reasoning controls
07 Prompt caching Cut cost on repeated context
08 Count tokens accurately count_tokens, not tiktoken
09 Retry on rate limits (429) Exponential backoff
10 Batch many prompts (50% off) Message Batches API
11 Analyze an image (vision) Image input
12 Fast text classification with Haiku Cheap, single-word labels

Run a recipe

git clone https://github.com/skycandykey1/llm-automation-cookbook
cd llm-automation-cookbook
pip install -r requirements.txt
export ANTHROPIC_API_KEY=sk-ant-...        # Windows: setx ANTHROPIC_API_KEY ...
python recipes/01_basic_message.py

Bonus: tested helpers

cookbook/utils.py ships two small, unit-tested helpers you can reuse:

  • estimate_cost(input_tokens, output_tokens, model) — USD cost from token counts
  • backoff_delay(attempt) — exponential backoff schedule for retries

Tests

Everything is verified offline — no API key, no network:

pip install -r requirements-dev.txt
python -m pytest -q
  • test_utils.py — unit tests for the helpers
  • test_recipes_lint.py — lints every recipe: approved model id, imports the SDK, has a docstring, and uses no deprecated params (temperature, budget_tokens, ...) or non-Anthropic libraries

License

MIT — see LICENSE.


💼 Built by skycandykey1 — available for AI agent & automation contract work. I build agents, MCP servers, and LLM automation. → skycandykey456@gmail.com · https://github.com/skycandykey1

About

Copy-paste Claude (Anthropic) API recipes in Python — structured output, tool use, caching, batching

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages