{"record":{"id":"1097ce6d4a268f2d","repo":"langchain-ai/deepagents","slug":"no-credentials-found-for-provider-provider-pl","errorCode":null,"errorMessage":"No credentials found for provider '{provider}'. Please set the {display_env} environment variable.","messagePattern":"No credentials found for provider '(.+?)'\\. Please set the (.+?) environment variable\\.","errorType":"exception","errorClass":"MissingCredentialsError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/config.py","lineNumber":5801,"sourceCode":"    if provider and provider not in IMPLICIT_AUTH_PROVIDERS:\n        cred_status = has_provider_credentials(provider)\n        if cred_status is False:\n            from deepagents_code.model_config import MissingCredentialsError\n\n            if provider == CODEX_PROVIDER:\n                # No env var to set; point the user at `/auth` instead.\n                msg = (\n                    \"Not signed in to ChatGPT. Run `/auth` and select \"\n                    \"openai_codex to sign in with your ChatGPT account.\"\n                )\n                raise MissingCredentialsError(msg, provider=provider, env_var=None)\n            env_var = get_credential_env_var(provider)\n            display_env = env_var or f\"<{provider} API key>\"\n            msg = (\n                f\"No credentials found for provider '{provider}'. \"\n                f\"Please set the {display_env} environment variable.\"\n            )\n            raise MissingCredentialsError(msg, provider=provider, env_var=env_var)\n\n    # Provider-specific kwargs (with per-model overrides)\n    kwargs = _get_provider_kwargs(provider, model_name=model_name)\n\n    # Compose under existing kwargs: profile < config.toml < --model-params\n    # (applied below). The app's OpenRouter profile is stacked on top of the\n    # built-in SDK profile so its `pre_init` (version check) and factory\n    # (app attribution) compose into a single `apply_provider_profile` call.\n    if provider:\n        from deepagents.profiles.provider import apply_provider_profile\n\n        if provider == \"openrouter\":\n            _ensure_cli_openrouter_profile_registered()\n\n        spec = f\"{provider}:{model_name}\" if model_name else provider\n        try:\n            kwargs = apply_provider_profile(spec, kwargs)\n        except ModelConfigError:","sourceCodeStart":5783,"sourceCodeEnd":5819,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/config.py#L5783-L5819","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\n$ dcode -m anthropic:claude-sonnet-4\n// MissingCredentialsError: No credentials found for provider 'anthropic'...\n// after\n$ export ANTHROPIC_API_KEY=sk-ant-...\n$ dcode -m anthropic:claude-sonnet-4","handlingStrategy":"validation","validationCode":"import os\nfrom deepagents_code.config import get_credential_env_var\n\ndef provider_credentials_present(provider: str) -> bool:\n    env_var = get_credential_env_var(provider)\n    return bool(env_var and os.environ.get(env_var))\n\nif not provider_credentials_present(\"anthropic\"):\n    raise SystemExit(\"Set ANTHROPIC_API_KEY (or run /auth) before starting.\")","typeGuard":null,"tryCatchPattern":"try:\n    model = build_model(provider, model_name)\nexcept MissingCredentialsError as exc:\n    if exc.env_var:\n        print(f\"Export {exc.env_var} or run /auth to store the key.\")\n    raise SystemExit(1)","preventionTips":["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."],"tags":["authentication","api-key","env-var","config"],"backgroundTag":"missing-env-var","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}