{"record":{"id":"dc7f9908e73060d1","repo":"langchain-ai/deepagents","slug":"unable-to-infer-a-model-provider-for-model-spec-r","errorCode":null,"errorMessage":"Unable to infer a model provider for {model_spec!r}. Specify one explicitly (e.g. 'anthropic:{model_spec}') or see the provider reference at {docs_url}.","messagePattern":"Unable to infer a model provider for (.+?)\\. Specify one explicitly \\(e\\.g\\. 'anthropic:(.+?)'\\) or see the provider reference at (.+?)\\.","errorType":"exception","errorClass":"UnknownProviderError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/config.py","lineNumber":5506,"sourceCode":"            else:\n                if hint.command is not None:\n                    install_hint = f\"Install with: {hint.command}\"\n                else:\n                    install_hint = f\"Install the '{package}' package manually\"\n                msg = (\n                    f\"Missing package for provider '{provider}'. \"\n                    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.","sourceCodeStart":5488,"sourceCodeEnd":5524,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/config.py#L5488-L5524","documentation":"Raised when `create_model` cannot determine which provider to use for a model spec. Both the app's auto-detection (`detect_provider`) and `init_chat_model`'s own inference failed, so a structured `UnknownProviderError` is raised so the UI can render the provider-reference docs URL as a clickable link.","triggerScenarios":"Calling `create_model()` or `create_model(model_spec)` with a bare model name (no `provider:` prefix) whose name matches no known prefix, no default model is configured, and no provider can be inferred from environment credentials — and `init_chat_model` also raises ValueError/TypeError during inference.","commonSituations":"Typos in model names ('claud-sonnet-4-5'), obscure or custom model IDs not in `detect_provider`'s prefix list, missing default in config.toml or env, using a new provider model before the app knows its prefix.","solutions":["Add an explicit provider prefix: use 'anthropic:my-model' instead of 'my-model'.","Set a default model spec in config.toml or the relevant env var so `create_model()` has a fully qualified default.","Check the model name for typos against the provider's official model list.","Install the provider package (e.g. langchain-anthropic) — missing packages can prevent inference."],"exampleFix":"// before\nmodel = create_model(\"my-weird-model-id\")\n// after\nmodel = create_model(\"anthropic:my-weird-model-id\")","handlingStrategy":"validation","validationCode":"def has_provider_hint(spec: str) -> bool:\n    if \":\" in spec:\n        return True\n    known_prefixes = (\"gpt-\", \"o1\", \"o3\", \"claude\", \"gemini\", \"grok\", \"command\", \"bedrock/\")\n    return spec.lower().startswith(known_prefixes)\n# call create_model only when has_provider_hint(spec), else pass \"provider:\" + spec","typeGuard":null,"tryCatchPattern":"try:\n    result = create_model(spec)\nexcept UnknownProviderError:\n    result = create_model(f\"anthropic:{spec}\")  # or prompt user for provider","preventionTips":["Always qualify non-standard model ids with an explicit 'provider:' prefix","Set a default model spec in config.toml so bare create_model() never needs inference","Keep the provider package installed so init_chat_model inference works","Verify model names against the provider's official docs"],"tags":["model-config","provider-inference","langchain"],"backgroundTag":"unknown-model-provider","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}