Registry / llm-agents / llama-index-llms-anthropic

llama-index-llms-anthropic

JSON →
library0.11.6pypypiunverified

The `llama-index-llms-anthropic` package provides an integration for using Anthropic's Claude models within the LlamaIndex framework. Anthropic is an AI research company focused on developing advanced language models, notably the Claude series, prioritizing safety and alignment. This integration allows LlamaIndex applications to leverage Anthropic's models for various LLM operations. The current version is `0.11.2`, and it follows LlamaIndex's rapid release cadence with frequent updates.

pip install llama-index-llms-anthropic llama-index
INSTALL
IMPORT
SIG · LLAMA-INDEX-LLMS-A
L
llama-index-llms-anthropic
llm-agentspythonv0.11.6
Install
26.6s avg
Import
7362ms
Disk
348MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 6.099s · 318.5MB
glibc
py 3.103.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.
fix
Migrate 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.
fix
Set 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.
fix
After 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.
fix
Always 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.
Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
llama-index-llms-anthropic — pip install llama-index-llms-anthropic · libregistry