> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ChatAnthropicVertex 集成

> 使用 LangChain Python 集成 ChatAnthropicVertex 对话模型。

> [!WARNING]
>
> **Claude 3 Haiku弃用:** 自2026年8月23日起，Anthropic将终止对Claude 3 Haiku的支持。请迁移至Claude Haiku 4.5（`claude-haiku-4-5@20251001`），该版本已在Gemini Enterprise Agent Platform上正式发布。详情请参阅[Anthropic的模型弃用政策](https://docs.anthropic.com/en/docs/resources/model-deprecations)。

> [Anthropic Claude](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/claude) models on Gemini Enterprise Agent Platform提供完全托管且无服务器部署的API模型。要在Gemini Enterprise Agent Platform上使用Claude模型，请直接向Gemini Enterprise Agent Platform API端点发送请求。由于Anthropic Claude模型采用托管API，无需自行部署或维护基础设施。

NOTE : Anthropic在Gemini Enterprise Agent Platform上的模型通过类`ChatAnthropicVertex`实现为聊天模型

```python theme={null}
!pip install -U langchain-google-vertexai anthropic[vertex]
```

```python theme={null}
from langchain.messages import (
    AIMessage,
    AIMessageChunk,
    HumanMessage,
    SystemMessage,
)
from langchain_core.outputs import LLMResult
from langchain_google_vertexai.model_garden import ChatAnthropicVertex
```

> [!NOTE]
>
> 指定正确的[Claude模型版本](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/claude#claude-opus)。尽可能使用包含日期后缀的模型标识符（例如`claude-haiku-4-5@20251001`）。

```python theme={null}
# TODO : Replace below with your project id and region
project = "<project_id>"
location = "<region>"

# Initialise the Model
model = ChatAnthropicVertex(
    model_name="claude-haiku-4-5@20251001",
    project=project,
    location=location,
)
```

```python theme={null}
# prepare input data for the model
raw_context = (
    "My name is Peter. You are my personal assistant. My favorite movies "
    "are Lord of the Rings and Hobbit."
)
question = (
    "Hello, could you recommend a good movie for me to watch this evening, please?"
)
context = SystemMessage(content=raw_context)
message = HumanMessage(content=question)
```

```python theme={null}
# Invoke the model
response = model.invoke([context, message])
print(response.content)
```

```text theme={null}
Since your favorite movies are the Lord of the Rings and Hobbit trilogies, I would recommend checking out some other epic fantasy films that have a similar feel:

1. The Chronicles of Narnia series - These films are based on the beloved fantasy novels by C.S. Lewis and have a great blend of adventure, magic, and memorable characters.

2. Stardust - This 2007 fantasy film, based on the Neil Gaiman novel, has an excellent cast and a charming, whimsical tone.

3. The Golden Compass - The first film adaptation of Philip Pullman's His Dark Materials series, with stunning visuals and a compelling story.

4. Pan's Labyrinth - Guillermo del Toro's dark, fairy tale-inspired masterpiece set against the backdrop of the Spanish Civil War.

5. The Princess Bride - A classic fantasy adventure film with humor, romance, and unforgettable characters.

Let me know if any of those appeal to you or if you'd like me to suggest something else! I'm happy to provide more personalized recommendations.
```

```python theme={null}
# You can choose to initialize/ override the model name on Invoke method as well
response = model.invoke([context, message], model_name="claude-sonnet-4-6")
print(response.content)
```

```text theme={null}
Sure, I'd be happy to recommend a movie for you! Since you mentioned that The Lord of the Rings and The Hobbit are among your favorite movies, I'll suggest some other epic fantasy/adventure films you might enjoy:

1. The Princess Bride (1987) - A classic fairy tale with adventure, romance, and a lot of wit and humor. It has an all-star cast and very quotable lines.

2. Willow (1988) - A fun fantasy film produced by George Lucas with fairies, dwarves, and brownies going on an epic quest. Has a similar tone to the Lord of the Rings movies.

3. Stardust (2007) - An underrated fantasy adventure based on the Neil Gaiman novel about a young man entering a magical kingdom to retrieve a fallen star. Great cast and visuals.

4. The Chronicles of Narnia series - The Lion, The Witch and The Wardrobe is the best known, but the other Narnia films are also very well done fantasy epics.

5. The Golden Compass (2007) - First installment of the His Dark Materials trilogy, set in a parallel universe with armored polar bears and truth-seeking devices.

Let me know if you'd like any other suggestions or have a particular style of movie in mind! I aimed for entertaining fantasy/adventure flicks similar to Lord of the Rings.
```

```python theme={null}
# Use streaming responses
stream = model.stream_events([context, message], version="v3", model_name="claude-haiku-4-5@20251001")
for token in stream.text:
    print(token, end="", flush=True)
```

***

> 官方原文：[src/oss/python/integrations/chat/google\_anthropic\_vertex.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/chat/google_anthropic_vertex.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.