# detect_provider

> **Function** in `deepagents_cli`

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

Auto-detect provider from model name.

Intentionally duplicates a subset of LangChain's
`_attempt_infer_model_provider` because we need to resolve the provider
**before** calling `init_chat_model` in order to:

1. Build provider-specific kwargs (API base URLs, headers, etc.) that are
   passed *into* `init_chat_model`.
2. Validate credentials early to surface user-friendly errors.

## Signature

```python
detect_provider(
    model_name: str,
) -> str | None
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model_name` | `str` | Yes | Model name to detect provider from. |

## Returns

`str | None`

Provider name (openai, anthropic, google_genai, google_vertexai,
nvidia) or `None` if the provider cannot be determined from the
name alone.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/829909166606f8a9d9571b00da725845bad08da7/libs/cli/deepagents_cli/config.py#L1768)