Use this file to discover all available pages before exploring further.
AgentOps provides seamless integration with Anthropic’s Python SDK, allowing you to track and analyze all your Claude model interactions automatically.
Then load the environment variables in your Python code:
from dotenv import load_dotenvimport os# Load environment variables from .env fileload_dotenv()# Set up environment variables with fallback valuesos.environ["ANTHROPIC_API_KEY"] = os.getenv("ANTHROPIC_API_KEY")os.environ["AGENTOPS_API_KEY"] = os.getenv("AGENTOPS_API_KEY")
import agentopsimport anthropic# Initialize AgentOpsagentops.init()# Create Anthropic clientclient = anthropic.Anthropic()# Make a streaming requestwith client.messages.stream( model="claude-sonnet-4-20250514", messages=[ {"role": "user", "content": "Write a short poem about artificial intelligence."} ]) as stream: for text in stream.text_stream: print(text, end="", flush=True) print()