Providers & runtime helpers¶
Factory functions read application.yaml / env.yaml so app code never hand-builds
clients.
from langstitch import (
get_config, get_env, get_secret, get_logger,
get_llm_provider, get_http_client, get_async_http_client,
)
cfg = get_config() # cached AppConfig
log = get_logger(__name__) # level from LOG_LEVEL
llm = get_llm_provider() # chat model from model: section (needs [llm])
http = get_http_client() # httpx.Client from http: section (needs [http])
key = get_secret("openai_api_key") # env lookup with sensible fallbacks
The same helpers are available as methods on LangStitchApp
(app.get_llm_provider(), app.get_http_client(), …).
LLM provider¶
from langstitch import get_llm_provider
# reads model.provider / model.name / model.temperature from config;
# the API key comes from the environment (populated by env.yaml)
llm = get_llm_provider() # or get_llm_provider("gpt-4o", temperature=0)
result = llm.invoke([{"role": "user", "content": "hi"}])
Requires the llm extra (pip install "langstitch-sdk[llm]") plus a provider package
such as langchain-openai.
Logging¶
from langstitch import get_logger
log = get_logger(__name__) # level from LOG_LEVEL env (default INFO)
log.info("handled request", extra={"intent": intent})
Env & secrets¶
from langstitch import get_env, get_secret
get_env("REGION", default="us-east-1")
get_secret("openai_api_key") # checks OPENAI_API_KEY and sensible fallbacks
Missing extras fail fast
Each helper imports its dependency lazily and raises a RuntimeError with an
install hint if the extra is missing. Treat that as a configuration error and
fix it at startup, not per request.
Related¶
- External services —
get_http_client("<service>") - Configuration — where these helpers read from