Canonical docs: https://apidoc.cometapi.com/integrations/langchain
Use this guide to configure LangChain with CometAPI by setting the base URL, API key, and model or provider options.
LangChain is a popular framework for building LLM-powered applications. CometAPI is fully compatible with langchain-openai — just point it at our base URL.
- Python 3.8+ and
langchain-openaiinstalled (pip install langchain-openai) - A CometAPI account with an active API key
Log in to the CometAPI dashboard. Click Add API Key and copy your key and base URL (https://api.cometapi.com).
Set your CometAPI key and base URL when initializing ChatOpenAI.
Option A — Environment variables (recommended):
export OPENAI_API_KEY=$COMETAPI_KEY
export OPENAI_API_BASE=https://api.cometapi.com/v1Option B — Inline configuration:
Run a simple chain (e.g., a prompt asking for the current date). A successful response confirms CometAPI is connected.
Tip Use
base_url="https://api.cometapi.com/v1"andapi_key=os.environ["COMETAPI_KEY"]when initializingChatOpenAIorOpenAIfromlangchain-openai. Any model ID from the CometAPI model list will work.



