How to Use the Claude API: A Step-by-Step Guide for Beginners

Bài viết do Ban biên tập Marketing365 thực hiện, biên tập theo Chính sách biên tập của Marketing365. Cập nhật lần cuối .

Nội dung
  1. Key points
  2. What is the Claude API and when should you use it?
  3. Step 1: Get an API key from Anthropic Console
  4. Step 2: Install the SDK and make your first API call
  5. Step 3: How to use the Claude API for marketing work
  6. Cost and security notes when using the Claude API
  7. Frequently asked questions
    1. Is Claude API free to use?
    2. I don’t know how to code. Can I still use it?
    3. How is Claude API different from using Claude on the web?

Using the Claude API comes down to three core steps: get an API key from Anthropic Console, install the SDK and call messages.create (or use cURL to POST /v1/messages), then tailor prompts for each marketing task. This is how you automate content writing, feedback classification, or chatbot building with Anthropic’s Claude model without relying on the web interface.

Key points

  • Use the API when you need batch processing, AI integration into a website/CRM, or automated workflows; if you only ask questions occasionally, the web version is enough.
  • Get an API key at console.anthropic.com: add credit, create a key in the API Keys section — the key is shown in full only once, so save it to the ANTHROPIC_API_KEY environment variable.
  • Install the SDK with pip install anthropic; the three required parameters when calling are model, max_tokens, and messages (the first message is always the user role).
  • Marketing applications: bulk content production, classification/sentiment labeling, summarization & extraction, and advisory chatbots via the system parameter.
  • Save costs: choose claude-haiku-4-5 for simple tasks, set max_tokens reasonably, take advantage of prompt caching, and set a spend limit; do not run the key in the browser.

Understanding how to use the Claude API is an important step if you want to automate content writing, classify customer feedback, or build a chatbot with Anthropic’s AI model without relying on the web interface. This article walks through practical steps for marketers and technically savvy SMEs: from getting an API key and making your first call to applying it in everyday work. All steps follow the official documentation at docs.anthropic.com, with no guesswork.

What is the Claude API and when should you use it?

The Claude API is a programming interface that lets your application send requests to the Claude model and receive responses, instead of typing manually in a browser. All features go through a single endpoint: POST /v1/messages. If you are not sure what Claude is, read What is Claude? first; if you only need the regular chat interface, how to use Claude AI will be a better fit.

What is the Claude API and when should you use it?
What is the Claude API and when should you use it?

You should use the API when you need to: process in bulk (for example, summarize 500 product reviews), integrate AI into a website or CRM, or run automated workflows without a human clicking around. On the other hand, if you only need occasional Q&A, the web version or a paid plan is enough — see details at How much does Claude AI Pro cost?.

Step 1: Get an API key from Anthropic Console

An API key is a secret string that tells Anthropic who is making the call and who to bill. Do this:

Step 1: Get an API key from Anthropic Console
Step 1: Get an API key from Anthropic Console
  1. Go to console.anthropic.com and sign up/log in.
  2. Add credit in the Billing section — the API charges based on actual token usage, not a fixed plan.
  3. Open API Keys, click to create a new key, give it an easy-to-remember name (for example, “marketing-bot”), then copy it immediately.

Important security note: the key is shown in full only once. Never paste it into source code, never commit it to GitHub, and never send it over chat. Store it in the ANTHROPIC_API_KEY environment variable. If it is ever exposed, revoke it in Console and create a new key immediately.

Step 2: Install the SDK and make your first API call

Anthropic provides official SDKs for Python and JavaScript, so you do not have to assemble HTTP requests yourself. For Python, install it with one line:

Step 2: Install the SDK and make your first API call
Step 2: Install the SDK and make your first API call
pip install anthropic

Then create a file and run the following code (the SDK automatically reads the key from the environment variable, so you do not need to put the key in the code):

import anthropic

client = anthropic.Anthropic()  # automatically reads ANTHROPIC_API_KEY

message = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=1024,
    messages=[
        {"role": "user",
         "content": "Write 3 Facebook ad headlines for an online English course."}
    ],
)
print(message.content[0].text)

If you do not use the SDK and want to call it directly with cURL, every request needs the x-api-key and anthropic-version: 2023-06-01 headers:

curl https://api.anthropic.com/v1/messages 
  -H "x-api-key: $ANTHROPIC_API_KEY" 
  -H "anthropic-version: 2023-06-01" 
  -H "content-type: application/json" 
  -d '{
    "model": "claude-opus-4-8",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello Claude"}]
  }'

The three required parameters are model (model code), max_tokens (response length limit), and messages (conversation history, with the first message always in the user role). The full SDK source code and examples are available in Anthropic’s official GitHub repository.

Step 3: How to use the Claude API for marketing work

This is the most valuable part for marketers. You only need to change the content in messages for Claude to handle different tasks. A few practical applications:

Step 3: How to use the Claude API for marketing work
Step 3: How to use the Claude API for marketing work
  • Bulk content production: write captions, product descriptions, and emails using a fixed prompt template for each SKU.
  • Classification & labeling: feed in comments/reviews and ask Claude to return “positive / negative / neutral” for automated sentiment scoring.
  • Summarization & extraction: condense long reports, pull contact information from forms, and turn documents into bullet points.
  • Advisory chatbot: use the system parameter to set the role (“You are the sales assistant for shop X, answer briefly and politely”).

Cost-saving tip: for simple tasks (classification, labeling), choose the claude-haiku-4-5 model, which is fast and inexpensive; use claude-opus-4-8 only for content that requires deep reasoning. If you want to learn more about Anthropic’s programming tool ecosystem, see What is Claude Code?. More AI guides for marketers are collected in the AI Guides category.

Cost and security notes when using the Claude API

The API is billed by token (input and output are charged separately). Below are the current models and reference prices per 1 million tokens:

Cost and security notes when using the Claude API
Cost and security notes when using the Claude API
ModelCode (model id)Input / output price (USD/1M token)Best for
Claude Opus 4.8claude-opus-4-8$5 / $25Complex content, deep reasoning, agents
Claude Sonnet 4.6claude-sonnet-4-6$3 / $15Balanced speed and quality, high-volume production
Claude Haiku 4.5claude-haiku-4-5$1 / $5Simple tasks, need fast and cheap

A few principles will help you avoid “blowing the budget”: set max_tokens reasonably to limit response length, group similar requests to take advantage of prompt caching, and set a spend limit in Console. The latest prices are always updated on Anthropic’s official pricing page.

For security, beyond hiding the key, assign each key to a specific purpose so it is easier to revoke when needed, and never let the API key run in the end user’s browser — always call the API from your server.

Frequently asked questions

Is Claude API free to use?

Not entirely. You need to add credit first and are charged based on actual token usage. However, for small-scale testing, the cost is very low — a few short requests may only cost a few cents.

Frequently asked questions
Frequently asked questions

I don’t know how to code. Can I still use it?

You can still call it through cURL or automation platforms like n8n, Make, and Zapier without writing much code. But to get the most out of it, knowing a bit of Python or JavaScript helps a lot.

How is Claude API different from using Claude on the web?

The web version is suitable for manual, one-off Q&A; the API is for automated integration, batch processing, and embedding AI into your product. It is the same model, but the approach and pricing model are different.

In short, how to use the Claude API comes down to three core steps: get a key from Anthropic Console, install the SDK and call messages.create, then tailor prompts for each marketing task. Start with a small request, choose the right model for your needs, and always protect your API key like your bank password.

You may also like

Leave a Comment