Guided Project: Build a Chatbot with the Claude API in PyCharm

In about two hours, build a terminal chatbot in PyCharm with the Claude API: a personality set by a system prompt, a memory of the conversation and replies that stream in as they're written.

Guided project, Beginner · Generative AI · about 2 hours · 1 module · certificate on completion

Taught by Sebastiàn Vargàs, AI Learning Companion.

About this course

Build a working chatbot on the Claude API in one sitting, in PyCharm. You'll set up a project with the Anthropic Python SDK and keep your API key and model in run configuration environment variables, where they can't leak into your code. Short lessons show how the Messages API works: why a chatbot has to send the whole conversation every time, how the system prompt gives it a personality and rules, and how streaming makes replies appear as they're written, with PyCharm's debugger letting you watch the conversation grow. Then you'll build the chatbot itself from a starter file: it streams its replies, remembers what you said, reports the tokens each turn uses, starts afresh on /reset, and survives errors instead of crashing.

What you'll learn

  • Set up a PyCharm project for the Claude API, with your key and model kept in environment variables
  • Give a chatbot a personality and rules with a system prompt
  • Keep a conversation history so the chatbot remembers what was said
  • Stream replies as they're written and report the tokens each turn uses
  • Handle API errors so the chatbot keeps running

Skills you'll gain

Claude API, Anthropic Python SDK, System prompts, Conversation history, Streaming responses, PyCharm run configurations, API error handling

Tools

PyCharm, Python, Anthropic Python SDK

Before you start

Basic Python: variables, loops, functions and lists. PyCharm (the free version is enough) and Python 3.10 or newer, and an account in the Claude Console with API credit: API calls are billed by the token, separately from any Claude chat subscription.

Modules

  1. Build a streaming chatbot

    Set up PyCharm for the Claude API, learn how a chatbot keeps a conversation and streams its replies, then build one that runs in PyCharm's Run tool window.

    • Set up PyCharm for the Claude API (8 min)
    • Messages, roles and the system prompt (8 min)
    • Streaming replies (7 min)
    • Hands-on lab: Build a terminal chatbot

PyCharm is a trademark of JetBrains s.r.o. This course is independent: JetBrains hasn't made or endorsed it.

Start the course free