Claude API Exercises

Fill in the blanks to complete the code.

1

Complete the Claude API client initialization

import Anthropic from "@anthropic-ai/sdk"; const client = new ();
2

Complete the messages.create() call with required fields

const msg = await client.messages.({ model: "claude-opus-4-5", max_tokens: 1024, messages: [{ role: "user", content: "Hello!" }] });
3

Access the text content from a Claude response

const text = message.content[0].;
4

Add a system prompt to guide Claude behavior

await client.messages.create({ model: "claude-opus-4-5", max_tokens: 512, : "You are a helpful coding assistant.", messages: [{ role: "user", content: "Write a loop" }] });
5

Set the correct role for a user message

const messages = [ { : "user", content: "What is recursion?" } ];
6

Name the stop_reason value when Claude uses a tool

// Claude wants to call a function if (response.stop_reason === "") { // execute the tool }
7

Enable streaming in a messages.stream() call

const stream = client.messages.({ model: "claude-opus-4-5", max_tokens: 1024, messages });
8

Identify the content block type for an image in Claude messages

content: [ { type: "", source: { type: "base64", media_type: "image/jpeg", data: b64 } }, { type: "text", text: "What is this?" } ]