Zack Saadioui
8/26/2024
1
2
bash
pip install anthropic1
2
3
python
import anthropic
client = anthropic.Anthropic(api_key='your_api_key_here')1
2
3
4
5
6
7
python
 response = client.messages.create(
     model="claude-3-5-sonnet-20240620",
     max_tokens=150,
     messages=[{"role": "user", "content": "Can you write a short poem about spring?"}]
 )
 print(response)1
2
3
4
5
6
python
 response = client.messages.create(
     model="claude-3-5-sonnet-20240620",
     messages=[{"role": "user", "content": "Write a Python function to add two numbers."}]
 )
 print(response)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
python
 response = client.messages.create(
     model="claude-3-5-sonnet-20240620",
     messages=[
         {
             "role": "user",
             "content": [{
                 "type": "image",
                 "source": {
                     "type": "base64",
                     "media_type": "image/jpeg",
                     "data": "base64_image_data_here"
                 }
             }, {
                 "type": "text",
                 "text": "What can you infer from this image?"
             }]
         }
     ]
 )
 print(response)Copyright © Arsturn 2025