← All exercises

Exercise 1 of 10 · 0 passed

Your First Claude API Call

The Anthropic Python SDK lets you call Claude in a few lines. At its core:

  • Create a client: anthropic.Anthropic()
  • Send messages: client.messages.create(...)
  • Read the reply: message.content[0].text

Why care? This is the foundation of every AI-powered app. Structured outputs, tool use, agents — everything builds on this one pattern.

Task

Complete get_completion(prompt) so it calls Claude and returns the text response.

Requirements:

  • Model: claude-sonnet-4-6
  • max_tokens=256
  • Return the text of the first content block
Ctrl + Enter
Click "Run tests". First time loads Python in your browser (~5s). After that, runs are instant on this page and ~1s on the others.