-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (28 loc) · 935 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import anthropic
# Initialize the Anthropic client
client = anthropic.Anthropic()
try:
# Create a message using the Anthropic API
message = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=1000,
temperature=0,
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 the content of the message
print(message.content)
except anthropic.BadRequestError as e:
# Handle insufficient credits error
print(f"Error: {e.message}")
print("Error: Insufficient credits to access the Claude API. Please go to Plans & Billing to upgrade or purchase credits.")