The Smallest Caption Call
request/response round trip
Part of: Caption & Alt-Text Generator
Once the payload is built, the round trip is short: send it, get text back, print it. This lesson is the smallest version of the whole product. It captions one image in about ten lines. The request/response shape You already know what a message with an image looks like from the last lesson. The reply comes back as a Message object, and the text you want sits at response.content[0].text, the first content block of the reply. Why content[0], not just content The reply's content is a list of blocks that mirrors the request. A plain text reply almost always has exactly one block of type "text", but the SDK keeps the list shape so replies mixing text with other block types fit the same structure. You'll write content[0].text in nearly every product in this track. What the raw response looks like Underneath the SDK object, the API returns JSON shaped roughly like this: The SDK parses this for you. Knowing the shape still helps, because when a bad key or a malformed reply breaks something, this exact structure is what you debug. Why this is the whole loop already This is the same six-step loop from the setup module: input (an image), prompt (the instruction), call (the API), parse (conten
Challenge: Parse the Model's Reply