langchain-ai/langchain
Configuration
Knobs that affect runtime behavior.
Environment variables
| Variable | Effect |
|---|---|
LANGCHAIN_TRACING_V2 / LANGSMITH_TRACING |
Enable LangSmith tracing for every Runnable invocation |
LANGSMITH_API_KEY (or LANGCHAIN_API_KEY) |
API key for LangSmith uploads |
LANGSMITH_ENDPOINT (or LANGCHAIN_ENDPOINT) |
Override the LangSmith API base URL |
LANGSMITH_PROJECT (or LANGCHAIN_PROJECT) |
Project name to attach traces to |
LANGCHAIN_DEBUG |
Print verbose debug events to stdout |
LANGCHAIN_VERBOSE |
Less verbose stdout printing |
LANGCHAIN_HANDLER |
Reserved for legacy handlers |
OPENAI_API_KEY |
Used by langchain-openai |
ANTHROPIC_API_KEY |
Used by langchain-anthropic |
GROQ_API_KEY, MISTRAL_API_KEY, XAI_API_KEY, DEEPSEEK_API_KEY, FIREWORKS_API_KEY, OPENROUTER_API_KEY, PERPLEXITY_API_KEY, EXA_API_KEY, NOMIC_API_KEY |
Per-partner API keys |
OLLAMA_HOST |
Base URL for the Ollama runtime (defaults to http://localhost:11434) |
HUGGINGFACEHUB_API_TOKEN |
Hugging Face Hub token |
LANGSMITH_TRACING_V2_DISABLED / LANGCHAIN_TRACING_V2_DISABLED |
Force-disable tracing for a specific subprocess |
The full set of LangSmith vars is documented in the langsmith SDK; LangChain reads them through the SDK rather than directly.
Global toggles
libs/core/langchain_core/globals.py exposes module-level functions:
from langchain_core.globals import set_debug, set_verbose, set_llm_cache, get_debug, get_verbose, get_llm_cache
set_debug(True) # register a debug tracer that prints events to stdout
set_verbose(True) # register a less verbose printer
set_llm_cache(InMemoryCache()) # process-wide LLM response cacheThese are convenience hooks for development. Production code attaches handlers via RunnableConfig.callbacks instead.
RunnableConfig
libs/core/langchain_core/runnables/config.py defines the per-invocation config TypedDict:
| Key | Purpose |
|---|---|
callbacks |
List of BaseCallbackHandler instances (or a CallbackManager) |
tags |
List of strings for filtering in LangSmith |
metadata |
Arbitrary dict attached to runs |
run_name |
Display name for the run |
run_id |
UUID identifier for the root run |
max_concurrency |
Cap for batch, abatch, RunnableParallel |
recursion_limit |
Cap for nested RunnableLambda recursion |
configurable |
Dict overriding ConfigurableField attributes on Runnables in the chain |
Pass it to any Runnable:
chain.invoke({"input": "..."}, config={"tags": ["pr-42"], "metadata": {"user": "alice"}})Cache backends
Built-in caches in libs/core/langchain_core/caches.py:
InMemoryCache— process-local, by-key cache.BaseCache— extend this to plug in Redis, SQLite, etc. (most concrete cache implementations live inlangchain-community).
Set globally via set_llm_cache(...), or per-model via model.cache = ....
Rate limiters
libs/core/langchain_core/rate_limiters.py provides InMemoryRateLimiter:
from langchain_core.rate_limiters import InMemoryRateLimiter
rate_limiter = InMemoryRateLimiter(
requests_per_second=10,
check_every_n_seconds=0.1,
max_bucket_size=10,
)
model = ChatOpenAI(rate_limiter=rate_limiter)The model awaits the rate limiter before each call.
Model-level kwargs
Every partner's chat model accepts:
model— model nametemperature,top_p,max_tokens— samplingtimeout,max_retries— HTTP behaviorapi_key,base_url,organization— auth and routingdefault_headers,default_query— request-level overridesstreaming,stream_usage— streaming behaviorcache— per-model cache overridecallbacks— per-model callback handlers (legacy; preferconfig["callbacks"])tags,metadata— defaults for every call
Provider-specific kwargs vary; see the partner page for each.
CI configuration
CI behavior is configured per-workflow under .github/workflows/:
check_diffs.yml— which packages run on which file changes_test.yml— Python version matrix (3.10, 3.11, 3.12, 3.13, 3.14)_test_pydantic.yml— Pydantic version matrixpr_lint.yml— allowed PR title types and scopespr_labeler.yml— automatic labeling rules
See also
- primitives/runnables —
RunnableConfigflow - primitives/callbacks-and-tracers — what
callbacksdoes - reference/dependencies — what each package pulls in
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.