langchain-ai/deepagents · error · MissingCredentialsError
No credentials found for provider '{provider}'. Please set t
Error message
No credentials found for provider '{provider}'. Please set the {display_env} environment variable. What it means
For non-Codex providers, deepagents-code raises MissingCredentialsError when no API key is found for the provider — neither the provider's known environment variable nor any stored credential. The message names the exact env var to set (resolved via get_credential_env_var), or a placeholder `<provider> API key` when no canonical env var is registered. The error carries `provider` and `env_var` so callers can offer targeted recovery.
Source
Thrown at libs/code/deepagents_code/config.py:5801
if provider and provider not in IMPLICIT_AUTH_PROVIDERS:
cred_status = has_provider_credentials(provider)
if cred_status is False:
from deepagents_code.model_config import MissingCredentialsError
if provider == CODEX_PROVIDER:
# No env var to set; point the user at `/auth` instead.
msg = (
"Not signed in to ChatGPT. Run `/auth` and select "
"openai_codex to sign in with your ChatGPT account."
)
raise MissingCredentialsError(msg, provider=provider, env_var=None)
env_var = get_credential_env_var(provider)
display_env = env_var or f"<{provider} API key>"
msg = (
f"No credentials found for provider '{provider}'. "
f"Please set the {display_env} environment variable."
)
raise MissingCredentialsError(msg, provider=provider, env_var=env_var)
# Provider-specific kwargs (with per-model overrides)
kwargs = _get_provider_kwargs(provider, model_name=model_name)
# Compose under existing kwargs: profile < config.toml < --model-params
# (applied below). The app's OpenRouter profile is stacked on top of the
# built-in SDK profile so its `pre_init` (version check) and factory
# (app attribution) compose into a single `apply_provider_profile` call.
if provider:
from deepagents.profiles.provider import apply_provider_profile
if provider == "openrouter":
_ensure_cli_openrouter_profile_registered()
spec = f"{provider}:{model_name}" if model_name else provider
try:
kwargs = apply_provider_profile(spec, kwargs)
except ModelConfigError:View on GitHub (pinned to a1af029e6e)
Solutions
- Export the env var named in the error message (e.g. `export ANTHROPIC_API_KEY=sk-...`) before launching dcode.
- Run `/auth` inside dcode to store the key persistently instead of relying on the environment.
- If the provider is wrong, correct the model spec / config.toml model entry to a provider you have credentials for.
- For custom OpenAI-compatible endpoints, ensure the canonical env var for that provider is set (see PROVIDER_API_KEY_ENV).
Example fix
// before $ dcode -m anthropic:claude-sonnet-4 // MissingCredentialsError: No credentials found for provider 'anthropic'... // after $ export ANTHROPIC_API_KEY=sk-ant-... $ dcode -m anthropic:claude-sonnet-4
Defensive patterns
Strategy: validation
Validate before calling
import os
from deepagents_code.config import get_credential_env_var
def provider_credentials_present(provider: str) -> bool:
env_var = get_credential_env_var(provider)
return bool(env_var and os.environ.get(env_var))
if not provider_credentials_present("anthropic"):
raise SystemExit("Set ANTHROPIC_API_KEY (or run /auth) before starting.") Try / catch
try:
model = build_model(provider, model_name)
except MissingCredentialsError as exc:
if exc.env_var:
print(f"Export {exc.env_var} or run /auth to store the key.")
raise SystemExit(1) Prevention
- Export provider API keys in your shell profile or .env so every dcode session inherits them.
- Prefer `/auth` for persistent credential storage that survives env changes.
- In CI, verify required secret env vars exist before the job builds a model.
- Double-check the provider part of model specs in config.toml matches a provider you configured.
When it happens
Trigger: Creating a chat model for a provider (e.g. `anthropic`, `openai`, `openrouter`) whose credential env var (e.g. ANTHROPIC_API_KEY) is unset in the process environment and no `/auth`-stored credential exists. Raised from the credential check in config.py when building the model.
Common situations: Running dcode in a fresh shell/container where API keys live in an rc-file that was not sourced; CI jobs missing secret env vars; renaming a model spec to a provider you never configured; a typo'd provider key in config.toml pointing at an unconfigured provider.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- No credentials configured. Please set one of: ANTHROPIC_API_
- Google Cloud location is required for provider 'google_anthr
- Not signed in to ChatGPT. Run `/auth` and select openai_code
- Runloop rejected the credentials; check RUNLOOP_API_KEY (or
- modes can only be provided when agent is a factory
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/1097ce6d4a268f2d.
Report an issue: GitHub.