Want to connect to sonnet 3.7 but getting connected to Opus 3

Hello, In my script I wanted to connect to sonnet 3.7 but getting connected to sonnet 3 or opus models. Below are the debug message. I also attached my python script. Is there anything wrong I am doing? How do I connect to sonnet 3.7 thinking through API. RIght now I am on free plan, checking cursor ai before I move to pro plan. Help is appreciated.

Debug: Checking model: claude-3-7-sonnet-20250219
Connected to: claude-3-sonnet-20240229
Checking model version…

Debug: Checking version for model: claude-3-7-sonnet-20250219
Model version: 20240513

Type ‘exit’ to quit, ‘clear’ to start a new conversation

++++++++

Phython script :import os
import sys
import anthropic
from dotenv import load_dotenv
import textwrap

Load API key from .env file or environment

load_dotenv()
ANTHROPIC_API_KEY = os.getenv(“ANTHROPIC_API_KEY”)

if not ANTHROPIC_API_KEY:
print(“Error: ANTHROPIC_API_KEY not found in environment variables”)
print(“Create a .env file with ANTHROPIC_API_KEY=your_key or set it in your environment”)
sys.exit(1)

Initialize client

client = anthropic.Anthropic(api_key=ANTHROPIC_API_KEY)
MODEL = “claude-3-7-sonnet-20250219”

Thinking mode system prompt

THINKING_PROMPT = “”“Please use your reasoning capabilities to think through this problem step by step.
Consider multiple perspectives, potential issues, and solutions before providing your final answer.”“”

def chat_with_claude(messages, temperature=0.7):
try:
print(f"\nDebug: Using model: {MODEL}“) # Debug line
response = client.messages.create(
model=MODEL,
temperature=temperature,
system=THINKING_PROMPT,
max_tokens=4000,
messages=messages
)
return response
except Exception as e:
print(f"Error: {e}”)
return None

def check_model():
try:
print(f"\nDebug: Checking model: {MODEL}“) # Debug line
response = client.messages.create(
model=MODEL,
temperature=0.7,
max_tokens=100,
messages=[{“role”: “user”, “content”: “What is your exact model name? Please respond with just the model name in the format ‘claude-3-7-sonnet’.”}]
)
return response.content[0].text
except Exception as e:
return f"Error checking model: {str(e)}”

def check_model_version():
try:
print(f"\nDebug: Checking version for model: {MODEL}“) # Debug line
response = client.messages.create(
model=MODEL,
temperature=0.7,
max_tokens=100,
messages=[{“role”: “user”, “content”: “What is your exact model version? Please respond with just the version number in the format ‘20250219’.”}]
)
return response.content[0].text
except Exception as e:
return f"Error checking model version: {str(e)}”

def main():
print(f"Claude Chat")
print(“Checking model connection…”)
model_info = check_model()
print(f"Connected to: {model_info}“)
print(“Checking model version…”)
version_info = check_model_version()
print(f"Model version: {version_info}”)
print(“\nType ‘exit’ to quit, ‘clear’ to start a new conversation\n”)

messages = []

while True:
    user_input = input("\nYou: ")
    
    if user_input.lower() == 'exit':
        break
    elif user_input.lower() == 'clear':
        messages = []
        print("Conversation cleared")
        continue
    
    # Add user message to history
    messages.append({"role": "user", "content": user_input})
    
    # Get response
    response = chat_with_claude(messages)
    
    if response:
        assistant_message = response.content[0].text
        print("\nClaude:")
        print(textwrap.fill(assistant_message, width=100))
        
        # Add assistant response to history
        messages.append({"role": "assistant", "content": assistant_message})
    else:
        print("Failed to get response")

if name == “main”:
main()

1 Like