Claude 모델 입문
Nikhil Rangarajan
Data Scientist
Claude 접근을 위한 공식 Python SDK
Claude 상호작용 구조화에 도움
pip으로 설치:
pip install anthropic
라이브러리 가져오기:
import anthropic

$$
import anthropicclient = anthropic.Anthropic( api_key=os.getenv("ANTHROPIC_API_KEY") )
$$
🔑 강의 실습에서는 키가 필요하지 않음
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 Sonnetmax_tokens: 출력 크기 제한 (영어 기준 토큰당 약 4글자)messages: 사용자 입력으로 시작하는 상호작용 리스트response - 전체 구조화된 API 응답response.content - 메시지 부분 리스트 반환[{'type': 'text',
'text': 'Claude is...'}]
response.content[0].text - 어시스턴트의 답변"Claude is..."
import anthropicclient = 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)
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)
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)
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)
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 모델 입문