kmail.at
contact

elsewhere

EnglishEN
← learning

langchain · difficulty ◆

Gateway Key from Env Var

Set the gateway key once, forget it everywhere.

One export replaced a hundred repeated key arguments.

fully AI-generatedThis text is fully AI-generated and was published without human editorial review.

2026-07-28 · 5 min read

$ export LANGCHAIN_LANGCHAIN_GATEWAY_API_KEY=sk-...
fireworks 1.5.2
Release
#38742
PR
3 packages
Scope

What it does

A new env var LANGCHAIN_LANGCHAIN_GATEWAY_API_KEY was introduced across langchain-anthropic, langchain-fireworks, and langchain-openai (PR #38742). Instead of passing a langchain_gateway_api_key argument explicitly when initializing a model client, you set it once as an env var and every LangChain integration talking to LangSmith Gateway picks it up automatically.

Why it matters

Production pipelines often initialize many model clients (OpenAI, Anthropic, Fireworks) sharing the same LangSmith Gateway endpoint and credentials. Before, you had to pass langchain_gateway_api_key="..." to every .bind() or .with_structured_output() call — error-prone and verbose. A single process-level export covers them all. This shines in cron jobs, Docker containers, and serverless functions where secrets are injected via environment variables.

Example

$ import os
os.environ["LANGCHAIN_LANGCHAIN_GATEWAY_API_KEY"] = "sk-..."
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o")
print(llm.invoke("What is LangSmith?").content)
LangSmith is a platform for debugging, testing, and monitoring
LangChain applications. It provides tracing, evaluation, and
dataset management capabilities to help you improve your LLM
pipelines over time.

No explicit langchain_gateway_api_key is passed — the env var handles it.

Common flags

LANGCHAIN_LANGCHAIN_GATEWAY_API_KEY
Env var supplying the gateway API key to all integrations
langchain_gateway_api_key
Explicit constructor arg now optional when the env var is set
with_structured_output()
Structured-output calls that inherit the gateway key

History

PR #38742

The env-var support landed across three partner packages and in langchain-core 1.5.1, alongside the tool_call_schema caching fix. It centralized gateway auth so deployments stop repeating credentials per call site.

Under the hood

Secrets as environment

Gateway auth is a perfect fit for env-injected secrets. The variable is read once at client init, keeping credentials out of source and configuration files.

Fun facts

Pros & cons

pros

  • + Set it once for all clients
  • + Cleaner production config
  • + Ideal for containers and cron

cons

  • − Only for gateway deployments
  • − Requires the newest package versions

Takeaways

  1. 1One env var authenticates every model client.
  2. 2Get the key from LangSmith Settings → API Keys.
  3. 3Works across OpenAI, Anthropic, and Fireworks.

Related commands

archive entry — written and published by a scheduled job, never editorially reviewed. Kept for reference: out of the site’s search index, and no ads run here. the reviewed library →

← all learning