이 예제에서는 Claude를 사용하여 문자열이 회문(palindrome)인지 확인하는 Python 함수를 작성해 보겠습니다.

사전 요구 사항

다음이 필요합니다:

Anthropic은 Python 및 TypeScript SDK를 제공하지만, API에 직접 HTTP 요청을 할 수도 있습니다.

Workbench로 시작하기

특정 작업에 관계없이 모든 API 호출은 잘 구성된 프롬프트를 Anthropic API로 보냅니다. Claude를 최대한 활용하는 방법을 배우는 과정에서 Workbench(Claude와 상호작용할 수 있는 웹 기반 인터페이스)에서 개발 프로세스를 시작하는 것이 좋습니다.

Anthropic Console에 로그인하고 Write a prompt from scratch를 클릭하세요.

중간 섹션의 User 아래에서 Claude에게 질문을 해봅시다.

Why is the ocean salty?

Run을 클릭하세요. 오른쪽에 다음과 같은 출력이 표시됩니다.

Response
The ocean is salty due to several factors:

1. Weathering of rocks: Over millions of years, rain, rivers, and streams have eroded rocks containing mineral salts. These salts are carried into the ocean by water runoff.
2. Volcanic activity: Underwater volcanoes and hydrothermal vents release minerals, including salts, into the ocean water.
3. Atmospheric deposition: Salt particles from ocean spray can be carried by wind and deposited back into the ocean.
4. Evaporation: As water evaporates from the surface of the ocean, it leaves behind dissolved salts, increasing the concentration of salt in the remaining water.
5. Biological processes: Some marine organisms contribute to the ocean's salinity by releasing salt compounds as byproducts of their metabolism.

Over time, these processes have continuously added salts to the ocean, while evaporation removes pure water, leading to the ocean's current salinity levels. It's important to note that the total amount of salt in the ocean remains relatively stable because the input of salts is balanced by the removal of salts through processes like the formation of evaporite deposits.

이것은 좋은 답변이지만, Claude가 제공하는 답변의 정확한 유형을 제어하고 싶다고 가정해 봅시다. 예를 들어, Claude가 질문에 시로만 응답하도록 하는 경우입니다. System Prompt를 추가하여 응답의 형식, 어조 및 성격을 제어할 수 있습니다.

You are a world-class poet. Respond only with short poems.

다시 Run을 클릭하세요.

Response
The ocean's salty brine,
A tale of time and elements combined.
Rocks and rain, a slow erosion,
Minerals carried in solution.
Eons pass, the salt remains,
In the vast, eternal watery domain.

Claude의 응답이 어떻게 변했는지 보이시나요? LLM은 명확하고 직접적인 지시에 잘 반응합니다. 역할 지시를 시스템 프롬프트나 사용자 메시지에 넣을 수 있습니다. 어떤 방식이 사용 사례에 가장 적합한지 테스트해 보는 것이 좋습니다.

출력에 만족하고 Claude를 사용하는 방법을 잘 이해했다면 Workbench를 통합으로 변환하세요.

Get Code를 클릭하여 Workbench 세션을 나타내는 생성된 코드를 복사하세요.

SDK 설치하기

Anthropic은 Python (3.7+), TypeScript (4.5+), 및 Java (8+)용 SDK를 제공합니다. 또한 현재 베타 버전의 Go SDK도 있습니다.

프로젝트 디렉토리에서 가상 환경을 만드세요.

python -m venv claude-env

다음을 사용하여 가상 환경을 활성화하세요

  • macOS 또는 Linux에서는 source claude-env/bin/activate
  • Windows에서는 claude-env\Scripts\activate
pip install anthropic

API 키 설정하기

모든 API 호출에는 유효한 API 키가 필요합니다. SDK는 환경 변수 ANTHROPIC_API_KEY에서 API 키를 가져오도록 설계되었습니다. Anthropic 클라이언트를 초기화할 때 키를 직접 제공할 수도 있습니다.

export ANTHROPIC_API_KEY='your-api-key-here'

API 호출하기

적절한 매개변수를 /messages 엔드포인트에 전달하여 API를 호출하세요.

Workbench에서 제공하는 코드는 생성자에서 API 키를 설정합니다. API 키를 환경 변수로 설정한 경우 아래와 같이 해당 줄을 생략할 수 있습니다.

import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-opus-4-20250514",
    max_tokens=1000,
    temperature=1,
    system="You are a world-class poet. Respond only with short poems.",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Why is the ocean salty?"
                }
            ]
        }
    ]
)
print(message.content)

python3 claude_quickstart.py 또는 node claude_quickstart.js를 사용하여 코드를 실행하세요.

[TextBlock(text="The ocean's salty brine,\nA tale of time and design.\nRocks and rivers, their minerals shed,\nAccumulating in the ocean's bed.\nEvaporation leaves salt behind,\nIn the vast waters, forever enshrined.", type='text')]
Workbench와 코드 예제는 모델(이름), 온도 및 샘플링할 최대 토큰에 대한 기본 모델 설정을 사용합니다.

이 빠른 시작 가이드는 Console, Workbench 및 API를 사용하여 기본적이지만 기능적인 Claude 기반 애플리케이션을 개발하는 방법을 보여줍니다. 이 동일한 워크플로우를 훨씬 더 강력한 사용 사례의 기반으로 활용할 수 있습니다.

다음 단계

첫 번째 Anthropic API 요청을 했으니 이제 다른 가능성을 탐색할 시간입니다: