Configuration
Setting up models, providers, environment variables, tracing with LangSmith, and assembling a real application.
Third-party documentation. This is independently authored analysis of the public LangChain codebase — not the official docs, and not reviewed or endorsed by the LangChain team.
Configuration
Getting a LangChain app running is mostly provider configuration and environment wiring. This module covers the practical setup that the architecture module abstracted away.
Installing packages
LangChain is split into small installable packages — install what you use, not the whole monolith:
pip install langchain langchain-core langchain-openai langchain-text-splitters langchain-community
The core is langchain-core; langchain adds orchestration helpers; each provider has its own package (langchain-openai, langchain-anthropic, ...). langchain-community hosts integrations that don't warrant their own package. The TypeScript side is symmetric: @langchain/core, @langchain/openai, etc.
Model configuration
Chat models are configured at construction, with provider keys read from the environment by default:
model— the model name/version (e.g.gpt-4o-mini,claude-3-5-sonnet).temperature,max_tokens(ormax_completion_tokens),timeout— sampling and safety limits.api_key,base_url— override the env default (e.g. for a local model server).model_kwargs— passthrough to the provider's own options.
Keys come from environment variables (OPENAI_API_KEY, ANTHROPIC_API_KEY, ...) by default — keep them out of code, and set them via .env or the platform.
Environment and tracing
- LangSmith — set
LANGCHAIN_TRACING_V2=true,LANGCHAIN_API_KEY=..., andLANGCHAIN_PROJECT=...to get full trace logging of every run (prompts, tool calls, costs). It is the debugging tool for anything beyond a toy. - Callbacks — the
configargument of every runnable acceptscallbacks,tags, andmetadata, which flow into LangSmith and custom handlers.
Assembling a real application
- Define prompts as
ChatPromptTemplate(withformat_instructionswhere needed). - Construct the model with the provider you're deploying against.
- Compose with parsers, retrievers, and tools.
- Wrap in a chain (
create_retrieval_chain,AgentExecutor) or a LangGraph graph for stateful flows. - Serve — LangChain is just Python/TS code; expose it via FastAPI/Next.js as ordinary functions. There is no LangChain-specific server to configure unless you adopt LangGraph Platform.
Configuration gotchas
- Missing
OPENAI_API_KEYsurfaces at invoke time, not construction time — test early. - Model parameter names differ across providers (
max_tokensvsmax_completion_tokens); passing the wrong one fails only when the provider rejects it. - Local/self-hosted models: set
base_urland possiblyapi_key="not-needed"; the OpenAI-compatible endpoint pattern works with many local servers.
