# API Key Management

Endpoints to manage your accounts API keys.

## List API Keys

`GET /v3/api-keys`

Returns all API keys belonging to the authenticated user with associated permissions.

**Responses**

- **200**: Ok

  Example (API key summaries):
  ```json
  [{"apiKeyId":"QNl8Xfl729CJlNgwkA329EL1D8z8BAQ2","label":"Trading Key","permissions":["TRADING","MARKET_DATA"]}]
  ```
- **401**: Unauthorized

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid JWT):
  ```json
  {"code":"INVALID_JWT_TOKEN","description":"Invalid JWT"}
  ```

**Example**

```bash
curl "https://api.demo.omniaexchange.com/api/v3/api-keys" \
  -H "Authorization: Bearer <token>"
```

---

## Create API Key

`POST /v3/api-keys`

Creates a new API key with the specified label and permissions. The requested permissions must be a subset of the permissions on the API key used to authenticate this request. Store the returned secret securely as it will not be shown again.

**Request Body** _(required)_

  | Field | Type | Description |
  |-------|------|-------------|
  | `label` | string | Label for the new API key (e.g. `Trading Key`) |
  | `permissions` | string[] | Permissions to grant to the new API key. Must be a subset of the permissions on the API key used to make this request. |

**Responses**

- **201**: Created

  | Field | Type | Description |
  |-------|------|-------------|
  | `apiKeyId` | string | The API key id (e.g. `QNl8Xfl729CJlNgwkA329EL1D8z8BAQ2`) |
  | `apiKeySecret` | string | The API key secret. Store this securely, it will not be shown again. (e.g. `u0WgWWLXYhcS+UnAGk2H+eZ3JZp1P4kpUxcoNitzu3U=`) |
  | `label` | string | Label for the new API key (e.g. `Trading Key`) |
  | `permissions` | string[] | Permissions granted to this API key |


  Example (API key created):
  ```json
  {"apiKeyId":"QNl8Xfl729CJlNgwkA329EL1D8z8BAQ2","apiKeySecret":"u0WgWWLXYhcS+UnAGk2H+eZ3JZp1P4kpUxcoNitzu3U=","label":"Trading Key","permissions":["TRADING","MARKET_DATA"]}
  ```
- **400**: Bad request

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid schema):
  ```json
  {"code":"INVALID_SCHEMA","description":"Missing or malformed schema"}
  ```
- **401**: Unauthorized

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid JWT):
  ```json
  {"code":"INVALID_JWT_TOKEN","description":"Invalid JWT"}
  ```
- **403**: Requested permissions exceed those of the authenticating API key

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid permissions):
  ```json
  {"code":"INVALID_PERMISSIONS","description":"Invalid permissions"}
  ```
- **500**: Internal server error

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Internal error):
  ```json
  {"code":"INTERNAL_SERVER_ERROR","description":"Internal Server Error"}
  ```

**Example**

```bash
curl -X POST "https://api.demo.omniaexchange.com/api/v3/api-keys" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"label": "Trading Key", "permissions": "<permissions>"}'
```

---

## List Permissions

`GET /v3/api-keys/permissions`

Returns all permissions that can be granted to an API key

**Responses**

- **200**: Ok

  | Field | Type | Description |
  |-------|------|-------------|
  | `permissions` | string[] | Permissions that can be granted to an API key. Internal permissions are not included. |


  Example (Permissions response):
  ```json
  {"permissions":["ACCOUNT_INFORMATION","ACCOUNT_MAINTENANCE","TRADING","MARKET_DATA","RFQ"]}
  ```
- **401**: Unauthorized

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid JWT):
  ```json
  {"code":"INVALID_JWT_TOKEN","description":"Invalid JWT"}
  ```
- **403**: Invalid permissions

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid permissions):
  ```json
  {"code":"INVALID_PERMISSIONS","description":"Invalid permissions"}
  ```

**Example**

```bash
curl "https://api.demo.omniaexchange.com/api/v3/api-keys/permissions" \
  -H "Authorization: Bearer <token>"
```

---

## Rotate Specified API Key

`POST /v3/api-keys/{apiKeyId}/rotate`

Generates a new secret for the specified API key. The old secret and jwt is immediately invalidated. Store the new secret securely as it will not be shown again. Requires the ACCOUNT_MAINTENANCE permission. To rotate the API key this request is authenticated with, use POST /v3/api-keys/rotate instead, which requires no permission.

**Parameters**

| Name | In | Required | Type | Description |
|------|-----|----------|------|-------------|
| `apiKeyId` | path | Yes | string | The id of the API key to rotate |

**Responses**

- **200**: Ok

  | Field | Type | Description |
  |-------|------|-------------|
  | `apiKeyId` | string | The API key id (e.g. `QNl8Xfl729CJlNgwkA329EL1D8z8BAQ2`) |
  | `apiKeySecret` | string | The new API key secret. Store this securely, it will not be shown again. (e.g. `u0WgWWLXYhcS+UnAGk2H+eZ3JZp1P4kpUxcoNitzu3U=`) |


  Example (API key rotated):
  ```json
  {"apiKeyId":"QNl8Xfl729CJlNgwkA329EL1D8z8BAQ2","apiKeySecret":"u0WgWWLXYhcS+UnAGk2H+eZ3JZp1P4kpUxcoNitzu3U="}
  ```
- **401**: Unauthorized

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid JWT):
  ```json
  {"code":"INVALID_JWT_TOKEN","description":"Invalid JWT"}
  ```
- **403**: Invalid permissions

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid permissions):
  ```json
  {"code":"INVALID_PERMISSIONS","description":"Invalid permissions"}
  ```
- **404**: API key not found or does not belong to this user

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Not found):
  ```json
  {"code":"NOT_FOUND","description":"Not Found"}
  ```
- **500**: Internal server error

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Internal error):
  ```json
  {"code":"INTERNAL_SERVER_ERROR","description":"Internal Server Error"}
  ```

**Example**

```bash
curl -X POST "https://api.demo.omniaexchange.com/api/v3/api-keys/{apiKeyId}/rotate" \
  -H "Authorization: Bearer <token>"
```

---

## Rotate Current API Key

`POST /v3/api-keys/rotate`

Generates a new secret for the API key used to authenticate this request. The old secret and jwt is immediately invalidated. Store the new secret securely as it will not be shown again. No permission is required: the caller already holds the secret of the key being rotated.

**Responses**

- **200**: Ok

  | Field | Type | Description |
  |-------|------|-------------|
  | `apiKeyId` | string | The API key id (e.g. `QNl8Xfl729CJlNgwkA329EL1D8z8BAQ2`) |
  | `apiKeySecret` | string | The new API key secret. Store this securely, it will not be shown again. (e.g. `u0WgWWLXYhcS+UnAGk2H+eZ3JZp1P4kpUxcoNitzu3U=`) |


  Example (API key rotated):
  ```json
  {"apiKeyId":"QNl8Xfl729CJlNgwkA329EL1D8z8BAQ2","apiKeySecret":"u0WgWWLXYhcS+UnAGk2H+eZ3JZp1P4kpUxcoNitzu3U="}
  ```
- **401**: Unauthorized

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid JWT):
  ```json
  {"code":"INVALID_JWT_TOKEN","description":"Invalid JWT"}
  ```
- **404**: The request was not authenticated with an API key

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Not found):
  ```json
  {"code":"NOT_FOUND","description":"Not Found"}
  ```
- **500**: Internal server error

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Internal error):
  ```json
  {"code":"INTERNAL_SERVER_ERROR","description":"Internal Server Error"}
  ```

**Example**

```bash
curl -X POST "https://api.demo.omniaexchange.com/api/v3/api-keys/rotate" \
  -H "Authorization: Bearer <token>"
```

---

