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

# LangChain (Anthropic)

> Use LangChain's ChatAnthropic with PipeLLM's Anthropic-compatible routes

For authentication and model list, see [Anthropic Overview](/api-reference/anthropic/overview).

<Note>
  This page is a framework integration guide. For the raw HTTP endpoint
  reference, see [Messages](/api-reference/anthropic/messages).
</Note>

## Installation

```bash theme={null}
pip install langchain-anthropic
```

## Code Examples

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import os
    from langchain_anthropic import ChatAnthropic

    llm = ChatAnthropic(
      model='claude-sonnet-4-5-20250929',
      anthropic_api_key=os.getenv('PIPELLM_API_KEY'),
      anthropic_api_url='https://api.pipellm.ai'
    )

    response = llm.invoke([
      ('user', 'Why is the sky blue?')
    ])

    print(response.content)
    ```
  </Tab>

  <Tab title="Node.js">
    ```javascript theme={null}
    import { ChatAnthropic } from '@langchain/anthropic';

    const llm = new ChatAnthropic({
      model: 'claude-sonnet-4-5-20250929',
      anthropicApiKey: process.env.PIPELLM_API_KEY,
      anthropicApiUrl: 'https://api.pipellm.ai'
    });

    const response = await llm.invoke([
      { role: 'user', content: 'Why is the sky blue?' }
    ]);

    console.log(response.content);
    ```
  </Tab>
</Tabs>

## Streaming

```python theme={null}
import os
from langchain_anthropic import ChatAnthropic

llm = ChatAnthropic(
  model='claude-sonnet-4-5-20250929',
  anthropic_api_key=os.getenv('PIPELLM_API_KEY'),
  anthropic_api_url='https://api.pipellm.ai',
  streaming=True
)

for chunk in llm.stream('Tell me a story'):
  print(chunk.content, end='', flush=True)
```

## Function Calling

```python theme={null}
import os
from langchain_anthropic import ChatAnthropic
from langchain_core.tools import tool

@tool
def get_weather(location: str) -> str:
  """Get the weather for a location."""
  return f"Weather in {location}: 22°C, Sunny"

llm = ChatAnthropic(
  model='claude-sonnet-4-5-20250929',
  anthropic_api_key=os.getenv('PIPELLM_API_KEY'),
  anthropic_api_url='https://api.pipellm.ai'
)

llm_with_tools = llm.bind_tools([get_weather])
response = llm_with_tools.invoke("What's the weather in Tokyo?")

print(response.tool_calls)
```

## Related Docs

<Columns cols={3}>
  <Card title="Anthropic Overview" icon="message" href="/api-reference/anthropic/overview">
    Headers, models, and native routes
  </Card>

  <Card title="Messages" icon="code" href="/api-reference/anthropic/messages">
    Raw endpoint reference for `POST /v1/messages`
  </Card>

  <Card title="Developer Tools Overview" icon="terminal" href="/integrations/overview">
    More tools and framework integrations on PipeLLM
  </Card>
</Columns>
