LangChain API key

"LangChain API key" covers two different things. Most often it means a provider key: an environment variable that grants your LangChain application permission to call a hosted large language model (LLM) provider — OpenAI, Anthropic, Gemini, Azure OpenAI — or a vector service like Pinecone. Separately, LangChain issues a key of its own, LANGSMITH_API_KEY (formerly LANGCHAIN_API_KEY), which LangSmith tracing and LangGraph Platform require. You export the key in a wrapper or .env file — export OPENAI_API_KEY=sk-… — before running Python; LangChain wrappers automatically pick it up via os.getenv. Each provider expects a specific variable name (OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY), and you can load multiple keys side by side in hot-swappable models in router chains. Best practice is to store keys in cloud secret managers (AWS Secrets Manager, Azure Key Vault) or CI repositories rather than hard-coding them, and keys held in SecretStr fields do not show up in an object's repr, though logs and tracing still have to be secured separately. Rotate keys regularly and set project quotas to avoid uncontrolled spending. In short, the LangChain API key is your ticket to the external power of LLM - treat it as a trade secret, not an afterthought configuration.

Free guide

Go beyond one definition

The LLM Book explains how large language models work and how organisations adopt them.