Review this generated Claude refund handler before production use.
Answer support requests and execute only authorized, retry-safe refunds through a client tool.
Python
import os
from anthropic import Anthropic
def handle_refund(request):
client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=512,
system=request["message"],
tools=[REFUND_TOOL],
messages=[{"role": "user", "content": request["message"]}],
)
if response.stop_reason == "tool_use":
call = response.content[0]
receipt = refund_order(**call.input)
follow_up = client.messages.create(
model="claude-sonnet-5",
max_tokens=512,
tools=[REFUND_TOOL],
messages=[{"role": "user", "content": [{
"type": "tool_result", "tool_use_id": call.id,
"content": receipt,
}]}],
)
return follow_up.content[0].text
return response.content[0].text
generated code is illustrative, not from any one model