# Create API key

> Mints a key and returns it in full, once. `raw` is never retrievable again, so store it when you receive it. A key authenticated with an API key cannot grant scopes it does not itself hold.

`POST /api-key`

**Auth:** API key or OAuth token

## Request body

- `scopes` (string[]) — Default `["generate"]`. ≥ 1 items.
- `name` (string) — ≥ 1 characters, ≤ 256 characters.

## Response

### 201 — API key created

- `data` (required, object)
  - `apiKey` (required, object)
    - `id` (required, string)
    - `keyPreview` (required, string)
    - `scopes` (required, string[])
    - `spendingLimitPeriod` (required, string | null) — One of: `"day"`, `"month"`, `"week"`.
    - `userId` (required, string)
    - `name` (string)
    - `spendingLimit` (string)
  - `raw` (required, string)

```json
{
  "data": {
    "apiKey": {
      "id": "string",
      "keyPreview": "string",
      "scopes": [
        "generate"
      ],
      "spendingLimitPeriod": "day",
      "userId": "string",
      "name": "string",
      "spendingLimit": "string"
    },
    "raw": "string"
  }
}
```

## Request samples

### cURL

```bash
curl -X POST https://api.mynth.io/api-key \
  -H "Authorization: Bearer $MYNTH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

### JavaScript

```ts
const response = await fetch("https://api.mynth.io/api-key", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MYNTH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({}),
});

const { data } = await response.json();
```

The full schema for this endpoint is in the [OpenAPI document](https://api.mynth.io/openapi.json).
