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

# LangChain

> Use NagaAI from LangChain for Python with ChatOpenAI or ChatAnthropic.

`ChatOpenAI` and `ChatAnthropic` take a custom base URL. See the LangChain docs for [ChatOpenAI](https://docs.langchain.com/oss/python/integrations/chat/openai) and [ChatAnthropic](https://docs.langchain.com/oss/python/integrations/chat/anthropic).

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

chat = ChatOpenAI(
    model="deepseek-v4.1-flash",
    base_url="https://api.naga.ac/v1",
    api_key=os.environ["NAGAAI_API_KEY"],
    stream_usage=True,
)
print(chat.invoke("Why do HTTP clients retry with backoff? One sentence.").content)

claude = ChatAnthropic(
    model="claude-sonnet-5",
    base_url="https://api.naga.ac",
    api_key=os.environ["NAGAAI_API_KEY"],
)
print(claude.invoke("Why do HTTP clients retry with backoff? One sentence.").content)
```

* `stream_usage=True` is needed for token usage in streams: `ChatOpenAI` turns it off for custom base URLs.
* `ChatOpenAI` reads only standard OpenAI fields, so it does not expose NagaAI's `reasoning_content`.
* `ChatAnthropic.get_num_tokens_from_messages` calls `count_tokens`, which returns `404` on NagaAI.
* With `use_responses_api=True`, send the full history each turn. NagaAI ignores `previous_response_id`.
