{"record":{"id":"87b39e6bbcb5790d","repo":"langchain-ai/deepagents","slug":"failed-to-initialize-model-spec-e","errorCode":null,"errorMessage":"Failed to initialize model '{spec}': {e}","messagePattern":"Failed to initialize model '(.+?)': (.+?)","errorType":"exception","errorClass":"ModelConfigError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/config.py","lineNumber":5513,"sourceCode":"                    f\"{install_hint}, then retry with `/model`.\"\n                )\n            raise MissingProviderPackageError(\n                msg, provider=provider, package=package\n            ) from e\n        raise ModelConfigError(msg) from e\n    except (ValueError, TypeError) as e:\n        if not provider:\n            # Both app auto-detection and `init_chat_model`'s own inference\n            # failed; surface a structured error so the UI can render the\n            # docs URL as a clickable link.\n            raise UnknownProviderError(model_spec=model_name) from e\n        spec = f\"{provider}:{model_name}\"\n        msg = f\"Invalid model configuration for '{spec}': {e}\"\n        raise ModelConfigError(msg) from e\n    except Exception as e:  # provider SDK auth/network errors\n        spec = f\"{provider}:{model_name}\" if provider else model_name\n        msg = f\"Failed to initialize model '{spec}': {e}\"\n        raise ModelConfigError(msg) from e\n\n\n@dataclass(frozen=True)\nclass ModelResult:\n    \"\"\"Result of creating a chat model, bundling the model with its metadata.\n\n    This separates model creation from runtime-state mutation so callers can\n    decide when to commit the metadata to process-wide state.\n\n    Attributes:\n        model: The instantiated chat model.\n        model_name: Resolved model name.\n        provider: Resolved provider name.\n        context_limit: Max input tokens from the model profile, or `None`.\n        unsupported_modalities: Input modalities not indicated as supported by\n            the model profile (e.g. `{\"audio\", \"video\"}`).\n        model_retries: Effective model-node retry count for the resolved\n            provider (see `_resolve_model_retries_from_section`). `0` disables","sourceCodeStart":5495,"sourceCodeEnd":5531,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/config.py#L5495-L5531","documentation":"Raised when model construction fails with an unexpected exception attributed to provider SDK auth or network errors. Unlike the ValueError/TypeError branch, this is a catch-all: the provider and model were valid, but instantiating the SDK client failed.","triggerScenarios":"`create_model('provider:model')` where the provider SDK raises during initialization — expired/invalid API key rejected at client construction, unreachable base URL, corrupted SDK install, or any non-ValueError/TypeError exception.","commonSituations":"Rotated or missing API keys, ANTHROPIC_BASE_URL/OPENAI_BASE_URL pointing to a dead proxy, corporate firewall blocking the endpoint, SDK version incompatibilities.","solutions":["Check credentials: run `/auth` or verify the provider's API key env var is set and valid.","Verify any custom base URL (e.g. OPENAI_BASE_URL) is reachable.","Read the chained exception for the SDK's specific message (auth vs network).","Reinstall/upgrade the provider package if the SDK itself is failing to import or initialize."],"exampleFix":"// before\nexport ANTHROPIC_API_KEY=sk-expired-key\n// after\nexport ANTHROPIC_API_KEY=sk-ant-valid-current-key","handlingStrategy":"try-catch","validationCode":"import os\nassert os.environ.get(\"ANTHROPIC_API_KEY\"), \"missing API key before create_model()\"","typeGuard":null,"tryCatchPattern":"try:\n    result = create_model(spec)\nexcept ModelConfigError as e:\n    cause = e.__cause__\n    if cause and \"auth\" in str(cause).lower():\n        prompt_reauth()  # e.g. run /auth\n    else:\n        schedule_retry_with_backoff()","preventionTips":["Verify API keys are set and current before launching","Test custom base URLs (OPENAI_BASE_URL etc.) for reachability","Keep provider SDK packages up to date","Distinguish auth vs network from the chained __cause__ before retrying"],"tags":["network","auth","sdk","model-init"],"backgroundTag":"model-provider-init-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}