# Store or replace the Monid API key.

> Write-only.
> https://koi.dog/docs/api/tools/set-monid-key/

`PUT /api/v1/tools/monid/key` · Scope: `config`

Monid is asked about the key first (`whoami`, then the balance and Monid's own controls when the key may read them; none is billed). A key Monid refuses is not stored (`400 key_refused`). `409 not_configured` on a server that does not offer Monid. Answers the connection, never the key. The timeline records the key ID, action and outcome.

## Headers.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Retry the same request with the same key. [Retry rules](https://koi.dog/docs/api/#retries). |

## Body.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `value` | `string` | yes | Your Monid API key. Monid is asked about it first with free calls; a key it refuses is not stored (`400 key_refused`). Encrypted at rest and never returned. 8 to 512 characters. |

## Response.

200 OK · JSON object

- **422 validation_failed**: Each schema error appears in `details`.

## Request.

```sh
curl -X PUT https://api.koi.dog/api/v1/tools/monid/key \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "value": "<your Monid API key>"
    }'
```

```js
const res = await fetch("https://api.koi.dog/api/v1/tools/monid/key", {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    value: "<your Monid API key>",
  }),
});
console.log(await res.json());
```

```python
import os

import requests

r = requests.put(
    "https://api.koi.dog/api/v1/tools/monid/key",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
    },
    json={
        "value": "<your Monid API key>",
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "enabled": false,
  "connectionId": "pc_monid",
  "status": "not_connected",
  "reason": "not_configured",
  "next": [],
  "base": "unconfigured",
  "hasSecret": false,
  "addedAt": "string",
  "observedAt": "string",
  "account": {
  },
  "wallet": {
  },
  "controls": {
  },
  "limits": {
    "crewUsd": 0,
    "monthlyUsd": 0,
    "callCeilingUsd": 0,
    "set": false
  },
  "month": {
    "periodStart": "string",
    "spentUsd": 0,
    "reservedUsd": 0
  },
  …
}
```
