AIMY: Every AI API response comes back as JSON. JSON is just structured text — a format for organizing data so your code can read it reliably. Once you can read JSON, you can extract exactly what you need from any AI response and pass it into the next step of your workflow. That's automation: step one feeds step two automatically.
ANALYZE
JSON and API Chaining
1
What JSON is
JavaScript Object Notation. A way to represent structured data as text:
{"key": "value", "list": [1, 2, 3]}. Python reads JSON as a dictionary.2
Parsing an API response
When Claude responds, the full message object has many fields.
message.content[0].text gives you the text. message.model tells you which model responded. message.usage.input_tokens tells you how many tokens you used.3
Chaining calls
Automation means the output of one API call becomes the input of the next. First call: "Summarize this document." Second call: "Based on this summary, generate three action items." The second prompt includes the first response.
4
Error handling
Automated workflows need to handle failures. If the API call fails, your script should catch the error and either retry or log the failure — not crash silently.
INTEGRATE
Build a Two-Step Workflow
- Create:
touch ai_workflow.py - Build step 1 — summarize:
import anthropic client = anthropic.Anthropic() def summarize(text): message = client.messages.create( model="claude-3-haiku-20240307", max_tokens=256, messages=[{"role": "user", "content": f"Summarize this in one sentence: {text}"}] ) return message.content[0].text
- Build step 2 — generate action items:
def generate_actions(summary): message = client.messages.create( model="claude-3-haiku-20240307", max_tokens=256, messages=[{"role": "user", "content": f"Given this summary: {summary}. List 3 specific action items."}] ) return message.content[0].text
- Add main block:
text = "Paste any paragraph here" summary = summarize(text) print("SUMMARY:", summary) actions = generate_actions(summary) print("ACTIONS:", actions)
- Run:
python ai_workflow.py - Observe: the output from Step 1 feeds directly into Step 2.
PTR (PROOF THAT IT RUNS)
- Both functions run without errors.
- The summary from step 1 is used in step 2's prompt.
- You can swap out the input text and the whole chain updates.
Common Mistakes
API rate limit
If you call the API too fast, add
import time and time.sleep(1) between calls.Long response truncated
Increase
max_tokens in your client.messages.create() call.CHECKPOINT
- You parsed a JSON-structured API response.
- You built a two-step automated workflow.
- You can explain what "chaining" means in an AI pipeline.
- You can modify the input and the whole workflow updates.
AIM COMMITMENT
Analyze: You understood JSON as structured data and API chaining as the foundation of automation.
Integrate: You built a real two-step AI workflow where output becomes input.
Manage: You can now build multi-step AI pipelines — not just single prompts.