SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
14 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
1.1 KB · 22 lines python
Raw Blame History
1#!/usr/bin/env python32"""Multi-turn conversation with the Python SDK (the history is replayed on every call; the API is stateless).34STATUS: LIVE_VERIFIED 2026-09-18 with anthropic 1.7.0 (.venv). Run: .venv/bin/python examples/anthropic/messages/multi_turn.py5Key comes from .env (loaded by scripts/live.py); never printed.6"""7import sys8from pathlib import Path910sys.path.insert(0, str(Path(__file__).resolve().parents[3]))11from scripts import live  # noqa: E402  (loads .env, gives log_request)12from anthropic import Anthropic  # noqa: E4021314client = Anthropic()15MODEL = "claude-haiku-4-5-20251001"16history = [{"role": "user", "content": "Remember the code word: PLUM."}, {"role": "assistant", "content": "Noted."},17           {"role": "user", "content": "Reply with only the code word."}]18msg = client.messages.create(model=MODEL, max_tokens=16, messages=history)19history.append({"role": "assistant", "content": msg.content})  # replay assistant blocks verbatim next turn20print(msg.content[0].text, "|", msg.stop_reason)21live.log_request("anthropic", "POST", "/v1/messages", 200, 0.00005, "example multi_turn.py")22