# set_stored_key

> **Function** in `deepagents_code`

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

Persist an API key for `provider`.

Empty / whitespace-only keys are rejected so callers don't accidentally
write a sentinel that masks a working environment variable (see
`apply_stored_credentials` in `model_config` — a stored empty would
unconditionally overwrite the env var).

## Signature

```python
set_stored_key(
    provider: str,
    key: str,
    *,
    base_url: str | None = None,
) -> WriteOutcome
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `provider` | `str` | Yes | Provider identifier (e.g., `"anthropic"`). |
| `key` | `str` | Yes | The API key value. Whitespace is stripped before storage. |
| `base_url` | `str \| None` | No | Optional provider endpoint to pair with the key. Whitespace is stripped; blank/`None` stores no endpoint, meaning the key uses the provider default rather than any inherited (e.g. gateway) URL. (default: `None`) |

## Returns

`WriteOutcome`

A `WriteOutcome` whose `warnings` tuple lists chmod failures the

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/0412009c5441bef8d75a427e1da8909e33ab5b56/libs/code/deepagents_code/auth_store.py#L355)