# MissingCredentialsError

> **Class** in `deepagents_code`

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

Raised when a provider is selected but its API key env var is unset.

Subclasses `ModelConfigError` so existing `except ModelConfigError` blocks
keep working. Carries the `provider` name and the canonical `env_var` so
callers can render targeted recovery hints (e.g., "set OPENAI_API_KEY" or
"run `/model <other_provider>:<model>`") without string-matching on the
formatted exception message and without re-deriving the env-var name.

## Signature

```python
MissingCredentialsError(
    self,
    message: str,
    *,
    provider: str,
    env_var: str | None = None,
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `message` | `str` | Yes | Human-readable message describing the missing credential. |
| `provider` | `str` | Yes | The provider whose credentials are missing (e.g., `'openai'`). |
| `env_var` | `str \| None` | No | The canonical env var name expected to hold the credential (e.g., `'OPENAI_API_KEY'`). `None` when the provider has no registered env-var mapping. (default: `None`) |

## Extends

- `ModelConfigError`

## Constructors

```python
__init__(
    self,
    message: str,
    *,
    provider: str,
    env_var: str | None = None,
) -> None
```

| Name | Type |
|------|------|
| `message` | `str` |
| `provider` | `str` |
| `env_var` | `str \| None` |


## Properties

- `provider`
- `env_var`

---

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