Registry /
llm-agents / llama-index-llms-anthropic
Install & Compatibility
Where this runs
tested against v0.11.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 6.099s · 318.5MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 26.6s · import 5.681s · 315MB
348MB installed
● package 348MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Anthropic
✓ from llama_index.llms.anthropic import Anthropic
Settings
✓ from llama_index.core import Settings
✗ from llama_index.core.service_context import ServiceContext
ServiceContext was deprecated in LlamaIndex v0.11 and replaced by Settings.
ChatMessage
✓ from llama_index.core.llms import ChatMessage
✗ from llama_index.llms.anthropic import ChatMessage
ChatMessage is a core LlamaIndex object, not specific to the Anthropic integration.
This quickstart demonstrates how to initialize the Anthropic LLM, set the Anthropic API key from an environment variable, configure the LlamaIndex global tokenizer for accurate token counting, and make a basic text completion call using a Claude 3 Opus model.
import os
from llama_index.llms.anthropic import Anthropic
from llama_index.core import Settings
os.environ["ANTHROPIC_API_KEY"] = os.environ.get("ANTHROPIC_API_KEY", "YOUR_ANTHROPIC_API_KEY")
# Initialize the Anthropic LLM
llm = Anthropic(model="claude-3-opus-20240229")
# Set the tokenizer for accurate token counting (important for Anthropic models)
Settings.tokenizer = llm.tokenizer
# Make a completion call
resp = llm.complete("What is the capital of France?")
print(resp)
Debug
Known issues
breakingLlamaIndex Core v0.10/v0.11 introduced significant breaking changes. `ServiceContext` was completely removed in favor of `Settings`, and `LLMPredictor` was deprecated. Code written for older LlamaIndex versions (pre-0.10) relying on these abstractions will break.fixMigrate from `ServiceContext` to `Settings` (e.g., `from llama_index.core import Settings`). Update `LLMPredictor` usage to directly use `LLM` classes or other LlamaIndex components. Consult the LlamaIndex migration guides.
affects: LlamaIndex Core <0.10
gotchaEnsure your `ANTHROPIC_API_KEY` is correctly configured. The `Anthropic` class primarily looks for the `ANTHROPIC_API_KEY` environment variable. If it's not set or invalid, API calls will fail with authentication errors.fixSet the `ANTHROPIC_API_KEY` environment variable or pass the `api_key` argument explicitly during `Anthropic` class initialization: `llm = Anthropic(api_key="sk-...")`.
affects: All versions
gotchaFor accurate token counting with Anthropic models (especially newer Claude 3 models), it is crucial to explicitly set the LlamaIndex global tokenizer to the Anthropic tokenizer. The default LlamaIndex tokenizer (often `tiktoken`) will lead to incorrect token counts and can cause context overflow errors or unexpected behavior.fixAfter initializing your `Anthropic` LLM instance, assign its tokenizer to `Settings.tokenizer`: `Settings.tokenizer = llm.tokenizer`.
affects: All versions
gotchaDependency conflicts, especially with the underlying `anthropic` Python client library, can arise when combining `llama-index-llms-anthropic` with other `llama-index` integrations (e.g., `llama-index-multi-modal-llms-anthropic`). Older versions of certain integrations might have strict, incompatible `anthropic` client version requirements.fixAlways check the specific version requirements of all `llama-index` packages and their dependencies. Consider upgrading all `llama-index-*` packages to their latest compatible versions or explicitly managing `anthropic` client versions to resolve conflicts.
affects: All versions, especially when combining with other `llama-index` integrations.
Upgrade
Version history
0.11.6latest on PyPI · released Jun 10, 2026
Audit
Dependencies
llama-index-corerequiredRequired for core LlamaIndex functionalities like Settings and ChatMessage objects.
anthropicrequiredThe underlying Python client library for interacting with Anthropic API.
pythonrequiredPython version compatibility.