ChatOpenAI and ChatAnthropic take a custom base URL, which is all LangChain needs to call NagaAI models from chains and agents. ChatOpenAI with use_responses_api=True calls the Responses API, and ChatAnthropic calls Messages. The LangChain docs cover both classes: ChatOpenAI and ChatAnthropic.
Before you start
You need a NagaAI API key exported asNAGA_API_KEY, and the langchain-openai or langchain-anthropic package.
Connect LangChain
1
Run a request
ChatOpenAI takes the base URL with /v1, and ChatAnthropic takes the host without it.2
Check the requests
Both requests appear in Logs in your dashboard.
Differences through NagaAI
NagaAI ignoresprevious_response_id, so leave use_previous_response_id off, as it is by default. ChatOpenAI then sends the full history each turn.
ChatAnthropic.get_num_tokens_from_messages calls count_tokens, which returns 404 on NagaAI.
Troubleshooting
401 invalid_api_key
NAGA_API_KEY is missing or wrong in the environment that runs your code. os.environ["NAGA_API_KEY"] raises KeyError when it isn’t set at all.
404 from get_num_tokens_from_messages
ChatAnthropic calls count_tokens, which NagaAI doesn’t serve. Count tokens with a local tokenizer instead.