첫 번째 요청 만들기

Claude 모델 입문

Nikhil Rangarajan

Data Scientist

Anthropic 라이브러리란?

  • Claude 접근을 위한 공식 Python SDK

  • Claude 상호작용 구조화에 도움

  • pip으로 설치:

    pip install anthropic
    
  • 라이브러리 가져오기:

    import anthropic
    

Diagram starting from a prompt, going to the Anthropic API, to the Claude model

Claude 모델 입문

인증 및 설정

$$

import anthropic

client = anthropic.Anthropic( api_key=os.getenv("ANTHROPIC_API_KEY") )

$$

🔑 강의 실습에서는 키가 필요하지 않음

Claude 모델 입문

첫 번째 프롬프트 보내기

response = client.messages.create(

model="claude-sonnet-4-6",
max_tokens=100,
messages=[{"role": "user", "content": "What DataCamp course do you recommend to learn Claude?"}]
)
  • model: Claude Sonnet
  • max_tokens: 출력 크기 제한 (영어 기준 토큰당 약 4글자)
    • 토큰: 모델이 처리하는 가장 작은 텍스트 단위
  • messages: 사용자 입력으로 시작하는 상호작용 리스트
Claude 모델 입문

모델 출력 추출하기

  • response - 전체 구조화된 API 응답
  • response.content - 메시지 부분 리스트 반환
    [{'type': 'text', 
    'text': 'Claude is...'}]
    
  • response.content[0].text - 어시스턴트의 답변
    "Claude is..."
    
Claude 모델 입문

모두 하나로 합치기

import anthropic


client = anthropic.Anthropic()
response = client.messages.create( model="claude-sonnet-4-6", max_tokens=100, messages=[{"role": "user", "content": "Summarize the benefits of Claude in one sentence."}] )
print(response.content[0].text)
Claude 모델 입문

모두 하나로 합치기

import anthropic #Importing

client = anthropic.Anthropic() 

response = client.messages.create( 
    model="claude-sonnet-4-6",
    max_tokens=100,
    messages=[{"role": "user", 
               "content": "Summarize the benefits of Claude in one sentence."}]
)

print(response.content[0].text) 
Claude 모델 입문

모두 하나로 합치기

import anthropic #Importing

client = anthropic.Anthropic() #Initializing

response = client.messages.create( 
    model="claude-sonnet-4-6",
    max_tokens=100,
    messages=[{"role": "user", 
               "content": "Summarize the benefits of Claude in one sentence."}]
)

print(response.content[0].text) 
Claude 모델 입문

모두 하나로 합치기

import anthropic #Importing

client = anthropic.Anthropic() #Initializing

response = client.messages.create( #Requesting
    model="claude-sonnet-4-6",
    max_tokens=100,
    messages=[{"role": "user", 
               "content": "Summarize the benefits of Claude in one sentence."}]
)

print(response.content[0].text) 
Claude 모델 입문

모두 하나로 합치기

import anthropic #Importing

client = anthropic.Anthropic() #Initializing

response = client.messages.create( #Requesting
    model="claude-sonnet-4-6",
    max_tokens=100,
    messages=[{"role": "user", 
               "content": "Summarize the benefits of Claude in one sentence."}]
)

print(response.content[0].text) #Extracting
Claude 모델 입문

연습해 볼까요?

Claude 모델 입문

Preparing Video For Download...