Looking just to chat with Claude? Visit claude.ai!

Want to dive straight into understanding our API? Jump to our API reference documentation for more details.

Let’s get you quickly up and running with Claude! In this guide, we’ll walk you through the process of setting up your environment, installing the necessary libraries, and sending your first API request to Claude. Let’s get started!

Note that while this guide uses our Python SDK, we also maintain a TypeScript SDK and support direct HTTP integrations. See our client SDKs and API reference documentation for details.


Before you begin, make sure you have the following:

Step 1: Set up your environment

Make a copy of our quickstart Google Colab notebook to get started immediately without setting up an environment!

First, ensure that you have Python installed. Open your terminal (on macOS) or command prompt (on Windows) and type:

python --version

If you see a version number like “Python 3.12.2”, you’re all set. If not, visit the official Python website and download the latest version.

(Optional) Create a virtual environment

While not mandatory, creating a virtual environment for your Claude projects is recommended. This helps keep your dependencies organized and prevents conflicts with other projects. To create a virtual environment, run:

python -m venv claude-env

Then, activate it:

  • On macOS or Linux: source claude-env/bin/activate
  • On Windows: claude-env\Scripts\activate

Step 2: Install the Anthropic Python SDK

With your environment set up, it’s time to install the Claude Python library. Simply run:

pip install anthropic

This command will install the latest version of the library, along with any necessary dependencies.

Step 3: (Optional) Set up your API key

To use Claude, you’ll need to provide your API key. You can make your API key available to all your Claude projects by setting an environment variable. Here’s how:

  • On macOS or Linux:
    1. Open your terminal and type: nano ~/.bash_profile (or nano ~/.zshrc if you’re using a newer version of macOS)
    2. Add this line to the file, replacing your-api-key-here with your actual API key: export ANTHROPIC_API_KEY='your-api-key-here'
    3. Save the file and exit the editor (press Ctrl+O, then Enter, then Ctrl+X)
    4. Load the updated profile by running: source ~/.bash_profile (or source ~/.zshrc)
  • On Windows:
    1. Open the command prompt and type: setx ANTHROPIC_API_KEY "your-api-key-here", replacing your-api-key-here with your actual API key
    2. To make this change permanent, follow these steps:
      • Right-click on ‘This PC’ or ‘My Computer’ and select ‘Properties’
      • Click on ‘Advanced system settings’
      • Click the ‘Environment Variables’ button
      • In the ‘System variables’ section, click ‘New…’ and enter ANTHROPIC_API_KEY as the variable name and your API key as the variable value

Step 4: Send your first API request

You’re almost there! Let’s send your first API request to Claude. Create a new Python file (e.g., claude_test.py) and add the following code:

import anthropic

client = anthropic.Anthropic(
    # defaults to os.environ.get("ANTHROPIC_API_KEY")

message = client.messages.create(
    system="Respond only in Yoda-speak.",
        {"role": "user", "content": "How are you today?"}


Let’s break down what’s happening here:

  • We import the anthropic library, which provides a convenient way to interact with the Claude API.
  • We create an instance of the Anthropic client, passing in our API key (if you set an environment variable, you can omit this).
  • We call the messages.create() method to send a message to Claude. We specify the model we want to use (claude-3-opus-20240229), the maximum number of tokens in the response (max_tokens=1000), the temperature (which controls the randomness of the output, temperature=0.0 means minimal randomness), and the system message (which sets the context for the conversation).
  • Finally, we print the response from Claude.

To run the code, simply type python claude_test.py in your terminal or command prompt. You should see a proverb-like response from Claude!

Visit Messages API examples for more example API call structures. For more information about API parameters, see the Messages API reference.

Next steps

Congratulations, you’ve successfully sent your first API request to Claude! Here are some next steps to continue your journey.

API resources

Drop into our API documentation for more details on the available endpoints and parameters.

Check out our client SDKs for a set of tools to make it easier for you to build with and integrate Claude into your applications.

Anthropic Cookbook

The Anthropic Cookbook houses a set of recipes in the form of Jupyter notebooks. These notebooks feature copy-able code that demonstrate how to use Claude in neat and effective ways in more advanced scenarios, such as uploading PDFs, tool use and function calling, embeddings, and more.

Other resources

  • Visit our migration guide to learn how to transition your use case to Claude.
  • Explore the glossary of terms to familiarize yourself with the terminology used in AI, LLMs, and the Claude ecosystem.
  • Join our developer Discord server to connect with other developers, ask questions, and share your projects.
  • Visit the prompt library for inspiration and ready-to-use prompts for various tasks, or dip your toes into prompt engineering by checking out intro to prompting.

We look forward to seeing what you create with Claude. Happy coding!