# Create an API key

Source: https://openpanel.sh/docs/api/api-keys/create-an-api-key

The key acts as you, never with more than your own access, capped by its scope and optionally limited to some projects. The key is in this answer only.

`POST https://openpanel.sh/api/v1/api-keys`

## Request body

JSON, `ApiKeyCreate`.

## Responses

| Status | Meaning | Body |
|---|---|---|
| 201 | Create an API key | `application/json`, `ApiKeyCreated` |
| 401 | No valid credential was sent. | `application/problem+json`, `Problem` |
| 403 | The credential may not do this. | `application/problem+json`, `Problem` |
| 409 | It clashes with something that exists, such as a name in use. | `application/problem+json`, `Problem` |
| 422 | The input was refused; detail says why. | `application/problem+json`, `Problem` |
| 429 | Too many requests; wait for Retry-After seconds. | `application/problem+json`, `Problem` |

## Schemas

### ApiKey

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "name": {
      "type": "string"
    },
    "prefix": {
      "type": "string",
      "description": "The key's first characters, to tell keys apart."
    },
    "scope": {
      "type": "string",
      "enum": [
        "view",
        "deploy",
        "admin"
      ]
    },
    "projectIds": {
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "expiresAt": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    },
    "lastUsedAt": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    },
    "revokedAt": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "createdBy": {
      "type": "string"
    },
    "creatorName": {
      "type": [
        "string",
        "null"
      ]
    },
    "creatorEmail": {
      "type": [
        "string",
        "null"
      ]
    }
  },
  "required": [
    "id",
    "name",
    "prefix",
    "scope",
    "projectIds",
    "expiresAt",
    "lastUsedAt",
    "revokedAt",
    "createdAt",
    "createdBy",
    "creatorName",
    "creatorEmail"
  ]
}
```

### ApiKeyCreate

```json
{
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 60,
      "description": "Where the key is used, such as \"GitHub Actions\"."
    },
    "scope": {
      "type": "string",
      "enum": [
        "view",
        "deploy",
        "admin"
      ],
      "description": "The most the key may do: view, deploy or admin. It never does more than its creator's own access."
    },
    "projectIds": {
      "description": "Limit the key to these projects.",
      "anyOf": [
        {
          "minItems": 1,
          "maxItems": 100,
          "type": "array",
          "items": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "expiresAt": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "name",
    "scope"
  ],
  "additionalProperties": false
}
```

### ApiKeyCreated

```json
{
  "type": "object",
  "properties": {
    "apiKey": {
      "$ref": "#/components/schemas/ApiKey"
    },
    "key": {
      "type": "string",
      "description": "The key itself (opk_…). Shown only in this answer; store it now."
    }
  },
  "required": [
    "apiKey",
    "key"
  ]
}
```

### Problem

```json
{
  "type": "object",
  "properties": {
    "type": {
      "type": "string",
      "description": "A link to the error's explanation in the docs."
    },
    "title": {
      "type": "string"
    },
    "status": {
      "type": "integer"
    },
    "code": {
      "type": "string",
      "description": "Stable machine-readable code: not_found, forbidden, invalid, conflict, rate_limited, not_implemented, …"
    },
    "detail": {
      "type": "string",
      "description": "What went wrong, in a sentence written for a person."
    }
  },
  "required": [
    "type",
    "title",
    "status",
    "code",
    "detail"
  ]
}
```