# create_model

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/config/create_model)

Create a chat model.

Uses `init_chat_model` for standard providers, or imports a custom
`BaseChatModel` subclass when the provider has a `class_path` in config.

Supports `provider:model` format (e.g., `'openai:gpt-5.5'`)
for explicit provider selection, or bare model names for auto-detection.

## Signature

```python
create_model(
    model_spec: str | None = None,
    *,
    extra_kwargs: dict[str, Any] | None = None,
    profile_overrides: dict[str, Any] | None = None,
    cli_max_retries: int | None = None,
    bind_preserved_thinking: bool = True,
) -> ModelResult
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model_spec` | `str \| None` | No | Model specification in `provider:model` format (e.g., `'anthropic:claude-sonnet-4-5'`, `'openai:gpt-5.5'`) or just the model name for auto-detection (e.g., `'claude-sonnet-4-5'`).      If not provided, uses environment-based defaults. (default: `None`) |
| `extra_kwargs` | `dict[str, Any] \| None` | No | Additional kwargs to pass to the model constructor.  These take highest priority, overriding values from the config file, except that provider-owned retry loops are disabled when known.  The provider's own retry-count kwarg (`RETRY_PARAM_BY_PROVIDER`, usually `max_retries`) is forced off after this merge whenever dcode can identify it, because the model-node middleware owns the retry budget and nested SDK retries would multiply its attempts. Supplying that kwarg here logs a warning; use `--max-retries` or `[retries]` instead. A provider dcode cannot identify (absent from the registry, no `[retries.<provider>].param`, and no `max_retries` already in the kwargs) keeps its own retry loop and logs a warning saying so. (default: `None`) |
| `profile_overrides` | `dict[str, Any] \| None` | No | Extra profile fields from `--profile-override`.  Merged on top of config file profile overrides (dcode wins). (default: `None`) |
| `cli_max_retries` | `int \| None` | No | Explicit `--max-retries` value. When absent, the provider-specific or global config value applies. (default: `None`) |
| `bind_preserved_thinking` | `bool` | No | Whether to apply the Anthropic preserved-thinking defaults (see `_apply_anthropic_thinking_binding`).  Pass `False` for a single-shot model that never replays thinking blocks across a prompt prefix change. Such a model gains nothing from the binding, and the injected `thinking` would push `with_structured_output` onto its unforced tool-call path. (default: `True`) |

## Returns

`ModelResult`

A `ModelResult` containing the model and its metadata.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/caaa7e7c12d214afa5cf0a1afed8eb6232aa6f7b/libs/code/deepagents_code/config.py#L6767)