Skip to content

Latest commit

 

History

History
40 lines (26 loc) · 1.85 KB

langchain.md

File metadata and controls

40 lines (26 loc) · 1.85 KB

Use LangChain with CometAPI

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.

Prerequisites

  • Python 3.8+ and langchain-openai installed (pip install langchain-openai)
  • A CometAPI account with an active API key

Setup

Get your CometAPI API key

Log in to the CometAPI dashboard. Click Add API Key and copy your key and base URL (https://api.cometapi.com).

CometAPI dashboard — Add API Key

CometAPI API key and base URL

Configure the base URL and API key

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/v1

Option B — Inline configuration:

LangChain code showing ChatOpenAI initialized with CometAPI base URL and key

Code example — ChatOpenAI initialization with CometAPI parameters

Test the connection

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" and api_key=os.environ["COMETAPI_KEY"] when initializing ChatOpenAI or OpenAI from langchain-openai. Any model ID from the CometAPI model list will work.