{"library":"langchain-anthropic","code":"import os\nfrom langchain_anthropic import ChatAnthropic\nfrom langchain_core.messages import HumanMessage, SystemMessage\n\n# Set your Anthropic API key as an environment variable\n# os.environ[\"ANTHROPIC_API_KEY\"] = \"YOUR_ANTHROPIC_API_KEY\"\n\n# Ensure the API key is set\nif not os.environ.get(\"ANTHROPIC_API_KEY\"):\n    raise ValueError(\"ANTHROPIC_API_KEY environment variable not set.\")\n\nmodel = ChatAnthropic(model=\"claude-3-sonnet-20240229\", temperature=0)\n\nmessages = [\n    SystemMessage(content=\"You are a helpful AI assistant.\"),\n    HumanMessage(content=\"What is the capital of France?\"),\n]\n\nresponse = model.invoke(messages)\nprint(response.content)","lang":"python","description":"This quickstart demonstrates how to instantiate and use the `ChatAnthropic` model to get a response from a Claude chat model. It highlights the importance of setting the `ANTHROPIC_API_KEY` environment variable.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}