langchain-ai/deepagents · error · ModelConfigError

Invalid model configuration for

Error message

Invalid model configuration for '{provider}:{model_name}': {e}

What it means

Raised when the provider was resolved but `init_chat_model` raised ValueError/TypeError while constructing the model, meaning the spec/provider is known but the model configuration is invalid for that provider. The original exception is chained for diagnosis.

Solutions

  1. Verify the model name is valid for the named provider and correct the spec.
  2. Read the chained exception (raised `from e`) for the underlying cause.
  3. Check extra_kwargs / config.toml model kwargs for invalid or renamed options.
  4. Upgrade the provider package (e.g. langchain-openai) in case the model id is newer than the integration supports.

Example fix

// before
model = create_model("anthropic:gpt-5.5")  # wrong provider for model
// after
model = create_model("openai:gpt-5.5")
Defensive patterns

Strategy: try-catch

Try / catch

try:
    result = create_model(spec)
except ModelConfigError as e:
    logger.error("%s (cause: %r)", e, e.__cause__)
    # fall back to a known-good default spec

Prevention

When it happens

Trigger: `create_model('provider:model')` where the provider package is installed but the constructor rejects the arguments — e.g. an unknown/unsupported model name for that provider, or invalid extra_kwargs / retry kwargs passed through.

Common situations: Model ID not offered by the named provider ('anthropic:gpt-4'), deprecated model removed from the provider SDK, config.toml kwargs incompatible with the provider class version.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/9afe0d627e4dd025. Report an issue: GitHub.

Appendix: source

Thrown at libs/code/deepagents_code/config.py:5509

                else:
                    install_hint = f"Install the '{package}' package manually"
                msg = (
                    f"Missing package for provider '{provider}'. "
                    f"{install_hint}, then retry with `/model`."
                )
            raise MissingProviderPackageError(
                msg, provider=provider, package=package
            ) from e
        raise ModelConfigError(msg) from e
    except (ValueError, TypeError) as e:
        if not provider:
            # Both app auto-detection and `init_chat_model`'s own inference
            # failed; surface a structured error so the UI can render the
            # docs URL as a clickable link.
            raise UnknownProviderError(model_spec=model_name) from e
        spec = f"{provider}:{model_name}"
        msg = f"Invalid model configuration for '{spec}': {e}"
        raise ModelConfigError(msg) from e
    except Exception as e:  # provider SDK auth/network errors
        spec = f"{provider}:{model_name}" if provider else model_name
        msg = f"Failed to initialize model '{spec}': {e}"
        raise ModelConfigError(msg) from e


@dataclass(frozen=True)
class ModelResult:
    """Result of creating a chat model, bundling the model with its metadata.

    This separates model creation from runtime-state mutation so callers can
    decide when to commit the metadata to process-wide state.

    Attributes:
        model: The instantiated chat model.
        model_name: Resolved model name.
        provider: Resolved provider name.
        context_limit: Max input tokens from the model profile, or `None`.

View on GitHub (pinned to a1af029e6e)