Reading the Full Response Object

Response

Part of: Your First API Call

In lesson 4 you grabbed one field, response.content[0].text, and printed it. That's the headline. But the response that comes back from Claude carries a whole receipt of useful information: an ID for support tickets, the exact model that answered, how many tokens you spent, and why the reply stopped. Read the whole object and you can debug, bill, and monitor a real app. What it is A Claude response is a JSON object (lesson 2) with a handful of top-level fields. The ones you'll use constantly: - id : a unique identifier for this exact call, like msg 01ABC.... Quote it when reporting a problem to support. - model : the exact model that produced the reply. Useful when you asked for an alias and want to know what actually ran. - role : always assistant on a reply (Claude is the one speaking). - content : the list of blocks holding the answer. content[0].text is the text of a plain reply. - usage : a small object: input tokens (what your prompt cost) and output tokens (what the reply cost). This is your bill. - stop reason : why generation ended: end turn (Claude finished naturally), max tokens (it hit your length cap and was cut off), and a few others. How it works Reach into the objec

Challenge: Response Inspector