# API Keys

## Create API Key

`client.apiKeys.create(APIKeyCreateParamsbody, RequestOptionsoptions?): APIKey`

**post** `/v1/api_keys`

Create a new API key

### Parameters

- `body: APIKeyCreateParams`

  - `expires_at: string`

    When the API Key expires and is no longer valid.

  - `name: string`

    API Key name.

  - `permissions: Array<Permission>`

    Scoped permissions for this API key. At least one is required.

    - `permission: APIPermissionLevel`

      Permission level: "read" or "edit".

      - `"read"`

      - `"edit"`

    - `resource_type: APIPermissionResourceType`

      Resource type this permission applies to.

      - `"vm"`

      - `"vpc"`

      - `"volume"`

      - `"connect_connection"`

      - `"rpc_node_dedicated"`

      - `"rpc_node_flex"`

      - `"nks_cluster"`

      - `"nks_node_pool"`

      - `"project"`

      - `"api_key"`

      - `"organization"`

      - `"audit_log"`

      - `"usage"`

  - `project_ids: Array<string>`

    Project IDs this API key is scoped to. At least one is required.

  - `source_ip_rule?: SourceIPRule`

    IP filter rules.

    - `allowed?: Array<string>`

      List of IPv4 CIDR addresses to allow.

    - `blocked?: Array<string>`

      List of IPv4 CIDR addresses to deny.

  - `starts_at?: string`

    When the API Key starts to be valid.

  - `tags?: Array<string>`

    Tags to attach to the API Key.

### Returns

- `APIKey`

  API Key response.

  - `id: string`

    API Key ID.

  - `created_at: string`

    When the API Key was created.

  - `expires_at: string`

    When the API Key expires and is no longer valid.

  - `managed: boolean`

    Whether this API key is system-managed.

  - `name: string`

    API Key name.

  - `permissions: Array<APIKeyPermission>`

    Scoped permissions for this API key.

    - `permission: APIPermissionLevel`

      Permission level: "read" or "edit".

      - `"read"`

      - `"edit"`

    - `resource_type: APIPermissionResourceType`

      Resource type this permission applies to.

      - `"vm"`

      - `"vpc"`

      - `"volume"`

      - `"connect_connection"`

      - `"rpc_node_dedicated"`

      - `"rpc_node_flex"`

      - `"nks_cluster"`

      - `"nks_node_pool"`

      - `"project"`

      - `"api_key"`

      - `"organization"`

      - `"audit_log"`

      - `"usage"`

  - `project_ids: Array<string>`

    Project IDs this API key is scoped to.

  - `source_ip_rule: SourceIPRuleResponse`

    IP filter rules.

    - `allowed: Array<string>`

      List of IPv4 CIDR addresses to allow.

    - `blocked: Array<string>`

      List of IPv4 CIDR addresses to deny.

  - `status: "active" | "inactive" | "expired"`

    Status of the API Key.

    - `"active"`

    - `"inactive"`

    - `"expired"`

  - `tags: Array<string>`

    Tags to attach to the API Key.

  - `updated_at: string`

    When the API Key was updated.

  - `key?: string`

    API Key. Only returned on creation.

  - `starts_at?: string`

    When the API Key starts to be valid.

### Example

```typescript
import NirvanaLabs from '@nirvana-labs/nirvana';

const client = new NirvanaLabs({
  apiKey: process.env['NIRVANA_LABS_API_KEY'], // This is the default and can be omitted
});

const apiKey = await client.apiKeys.create({
  expires_at: '2025-12-31T23:59:59Z',
  name: 'My API Key',
  permissions: [{ permission: 'edit', resource_type: 'vm' }],
  project_ids: ['123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174001'],
});

console.log(apiKey.id);
```

#### Response

```json
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "created_at": "2025-01-01T00:00:00Z",
  "expires_at": "2025-01-01T00:00:00Z",
  "managed": false,
  "name": "My API Key",
  "permissions": [
    {
      "permission": "edit",
      "resource_type": "vm"
    }
  ],
  "project_ids": [
    "string"
  ],
  "source_ip_rule": {
    "allowed": [
      "192.168.1.0/24",
      "10.0.0.0/8"
    ],
    "blocked": [
      "192.168.1.100/32"
    ]
  },
  "status": "active",
  "tags": [
    "production",
    "ethereum"
  ],
  "updated_at": "2025-01-01T00:00:00Z",
  "key": "6r17s0jy_b0_RbSofrrNvawFQcaN-VbGtUM7cKCW7_k",
  "starts_at": "2025-01-01T00:00:00Z"
}
```

## Get API Key Details

`client.apiKeys.get(stringapiKeyID, RequestOptionsoptions?): APIKey`

**get** `/v1/api_keys/{api_key_id}`

Get details about an API key

### Parameters

- `apiKeyID: string`

### Returns

- `APIKey`

  API Key response.

  - `id: string`

    API Key ID.

  - `created_at: string`

    When the API Key was created.

  - `expires_at: string`

    When the API Key expires and is no longer valid.

  - `managed: boolean`

    Whether this API key is system-managed.

  - `name: string`

    API Key name.

  - `permissions: Array<APIKeyPermission>`

    Scoped permissions for this API key.

    - `permission: APIPermissionLevel`

      Permission level: "read" or "edit".

      - `"read"`

      - `"edit"`

    - `resource_type: APIPermissionResourceType`

      Resource type this permission applies to.

      - `"vm"`

      - `"vpc"`

      - `"volume"`

      - `"connect_connection"`

      - `"rpc_node_dedicated"`

      - `"rpc_node_flex"`

      - `"nks_cluster"`

      - `"nks_node_pool"`

      - `"project"`

      - `"api_key"`

      - `"organization"`

      - `"audit_log"`

      - `"usage"`

  - `project_ids: Array<string>`

    Project IDs this API key is scoped to.

  - `source_ip_rule: SourceIPRuleResponse`

    IP filter rules.

    - `allowed: Array<string>`

      List of IPv4 CIDR addresses to allow.

    - `blocked: Array<string>`

      List of IPv4 CIDR addresses to deny.

  - `status: "active" | "inactive" | "expired"`

    Status of the API Key.

    - `"active"`

    - `"inactive"`

    - `"expired"`

  - `tags: Array<string>`

    Tags to attach to the API Key.

  - `updated_at: string`

    When the API Key was updated.

  - `key?: string`

    API Key. Only returned on creation.

  - `starts_at?: string`

    When the API Key starts to be valid.

### Example

```typescript
import NirvanaLabs from '@nirvana-labs/nirvana';

const client = new NirvanaLabs({
  apiKey: process.env['NIRVANA_LABS_API_KEY'], // This is the default and can be omitted
});

const apiKey = await client.apiKeys.get('api_key_id');

console.log(apiKey.id);
```

#### Response

```json
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "created_at": "2025-01-01T00:00:00Z",
  "expires_at": "2025-01-01T00:00:00Z",
  "managed": false,
  "name": "My API Key",
  "permissions": [
    {
      "permission": "edit",
      "resource_type": "vm"
    }
  ],
  "project_ids": [
    "string"
  ],
  "source_ip_rule": {
    "allowed": [
      "192.168.1.0/24",
      "10.0.0.0/8"
    ],
    "blocked": [
      "192.168.1.100/32"
    ]
  },
  "status": "active",
  "tags": [
    "production",
    "ethereum"
  ],
  "updated_at": "2025-01-01T00:00:00Z",
  "key": "6r17s0jy_b0_RbSofrrNvawFQcaN-VbGtUM7cKCW7_k",
  "starts_at": "2025-01-01T00:00:00Z"
}
```

## Update API Key

`client.apiKeys.update(stringapiKeyID, APIKeyUpdateParamsbody, RequestOptionsoptions?): APIKey`

**patch** `/v1/api_keys/{api_key_id}`

Update an existing API key

### Parameters

- `apiKeyID: string`

- `body: APIKeyUpdateParams`

  - `name?: string`

    API Key name.

  - `permissions?: Array<Permission>`

    Scoped permissions for this API key. When provided, replaces the entire set. At least one is required.

    - `permission: APIPermissionLevel`

      Permission level: "read" or "edit".

      - `"read"`

      - `"edit"`

    - `resource_type: APIPermissionResourceType`

      Resource type this permission applies to.

      - `"vm"`

      - `"vpc"`

      - `"volume"`

      - `"connect_connection"`

      - `"rpc_node_dedicated"`

      - `"rpc_node_flex"`

      - `"nks_cluster"`

      - `"nks_node_pool"`

      - `"project"`

      - `"api_key"`

      - `"organization"`

      - `"audit_log"`

      - `"usage"`

  - `project_ids?: Array<string>`

    Project IDs this API key is scoped to. When provided, replaces the entire set. At least one is required.

  - `source_ip_rule?: SourceIPRule`

    IP filter rules.

    - `allowed?: Array<string>`

      List of IPv4 CIDR addresses to allow.

    - `blocked?: Array<string>`

      List of IPv4 CIDR addresses to deny.

  - `tags?: Array<string>`

    Tags to attach to the API Key.

### Returns

- `APIKey`

  API Key response.

  - `id: string`

    API Key ID.

  - `created_at: string`

    When the API Key was created.

  - `expires_at: string`

    When the API Key expires and is no longer valid.

  - `managed: boolean`

    Whether this API key is system-managed.

  - `name: string`

    API Key name.

  - `permissions: Array<APIKeyPermission>`

    Scoped permissions for this API key.

    - `permission: APIPermissionLevel`

      Permission level: "read" or "edit".

      - `"read"`

      - `"edit"`

    - `resource_type: APIPermissionResourceType`

      Resource type this permission applies to.

      - `"vm"`

      - `"vpc"`

      - `"volume"`

      - `"connect_connection"`

      - `"rpc_node_dedicated"`

      - `"rpc_node_flex"`

      - `"nks_cluster"`

      - `"nks_node_pool"`

      - `"project"`

      - `"api_key"`

      - `"organization"`

      - `"audit_log"`

      - `"usage"`

  - `project_ids: Array<string>`

    Project IDs this API key is scoped to.

  - `source_ip_rule: SourceIPRuleResponse`

    IP filter rules.

    - `allowed: Array<string>`

      List of IPv4 CIDR addresses to allow.

    - `blocked: Array<string>`

      List of IPv4 CIDR addresses to deny.

  - `status: "active" | "inactive" | "expired"`

    Status of the API Key.

    - `"active"`

    - `"inactive"`

    - `"expired"`

  - `tags: Array<string>`

    Tags to attach to the API Key.

  - `updated_at: string`

    When the API Key was updated.

  - `key?: string`

    API Key. Only returned on creation.

  - `starts_at?: string`

    When the API Key starts to be valid.

### Example

```typescript
import NirvanaLabs from '@nirvana-labs/nirvana';

const client = new NirvanaLabs({
  apiKey: process.env['NIRVANA_LABS_API_KEY'], // This is the default and can be omitted
});

const apiKey = await client.apiKeys.update('api_key_id');

console.log(apiKey.id);
```

#### Response

```json
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "created_at": "2025-01-01T00:00:00Z",
  "expires_at": "2025-01-01T00:00:00Z",
  "managed": false,
  "name": "My API Key",
  "permissions": [
    {
      "permission": "edit",
      "resource_type": "vm"
    }
  ],
  "project_ids": [
    "string"
  ],
  "source_ip_rule": {
    "allowed": [
      "192.168.1.0/24",
      "10.0.0.0/8"
    ],
    "blocked": [
      "192.168.1.100/32"
    ]
  },
  "status": "active",
  "tags": [
    "production",
    "ethereum"
  ],
  "updated_at": "2025-01-01T00:00:00Z",
  "key": "6r17s0jy_b0_RbSofrrNvawFQcaN-VbGtUM7cKCW7_k",
  "starts_at": "2025-01-01T00:00:00Z"
}
```

## Delete API Key

`client.apiKeys.delete(stringapiKeyID, RequestOptionsoptions?): void`

**delete** `/v1/api_keys/{api_key_id}`

Delete an API key

### Parameters

- `apiKeyID: string`

### Example

```typescript
import NirvanaLabs from '@nirvana-labs/nirvana';

const client = new NirvanaLabs({
  apiKey: process.env['NIRVANA_LABS_API_KEY'], // This is the default and can be omitted
});

await client.apiKeys.delete('api_key_id');
```

## List API Keys

`client.apiKeys.list(APIKeyListParamsquery?, RequestOptionsoptions?): Cursor<APIKey>`

**get** `/v1/api_keys`

List all API keys

### Parameters

- `query: APIKeyListParams`

  - `cursor?: string`

    Pagination cursor returned by a previous request

  - `limit?: number`

    Maximum number of items to return

### Returns

- `APIKey`

  API Key response.

  - `id: string`

    API Key ID.

  - `created_at: string`

    When the API Key was created.

  - `expires_at: string`

    When the API Key expires and is no longer valid.

  - `managed: boolean`

    Whether this API key is system-managed.

  - `name: string`

    API Key name.

  - `permissions: Array<APIKeyPermission>`

    Scoped permissions for this API key.

    - `permission: APIPermissionLevel`

      Permission level: "read" or "edit".

      - `"read"`

      - `"edit"`

    - `resource_type: APIPermissionResourceType`

      Resource type this permission applies to.

      - `"vm"`

      - `"vpc"`

      - `"volume"`

      - `"connect_connection"`

      - `"rpc_node_dedicated"`

      - `"rpc_node_flex"`

      - `"nks_cluster"`

      - `"nks_node_pool"`

      - `"project"`

      - `"api_key"`

      - `"organization"`

      - `"audit_log"`

      - `"usage"`

  - `project_ids: Array<string>`

    Project IDs this API key is scoped to.

  - `source_ip_rule: SourceIPRuleResponse`

    IP filter rules.

    - `allowed: Array<string>`

      List of IPv4 CIDR addresses to allow.

    - `blocked: Array<string>`

      List of IPv4 CIDR addresses to deny.

  - `status: "active" | "inactive" | "expired"`

    Status of the API Key.

    - `"active"`

    - `"inactive"`

    - `"expired"`

  - `tags: Array<string>`

    Tags to attach to the API Key.

  - `updated_at: string`

    When the API Key was updated.

  - `key?: string`

    API Key. Only returned on creation.

  - `starts_at?: string`

    When the API Key starts to be valid.

### Example

```typescript
import NirvanaLabs from '@nirvana-labs/nirvana';

const client = new NirvanaLabs({
  apiKey: process.env['NIRVANA_LABS_API_KEY'], // This is the default and can be omitted
});

// Automatically fetches more pages as needed.
for await (const apiKey of client.apiKeys.list()) {
  console.log(apiKey.id);
}
```

#### Response

```json
{
  "items": [
    {
      "id": "123e4567-e89b-12d3-a456-426614174000",
      "created_at": "2025-01-01T00:00:00Z",
      "expires_at": "2025-01-01T00:00:00Z",
      "managed": false,
      "name": "My API Key",
      "permissions": [
        {
          "permission": "edit",
          "resource_type": "vm"
        }
      ],
      "project_ids": [
        "string"
      ],
      "source_ip_rule": {
        "allowed": [
          "192.168.1.0/24",
          "10.0.0.0/8"
        ],
        "blocked": [
          "192.168.1.100/32"
        ]
      },
      "status": "active",
      "tags": [
        "production",
        "ethereum"
      ],
      "updated_at": "2025-01-01T00:00:00Z",
      "key": "6r17s0jy_b0_RbSofrrNvawFQcaN-VbGtUM7cKCW7_k",
      "starts_at": "2025-01-01T00:00:00Z"
    }
  ],
  "pagination": {
    "next_cursor": "RhwniMT4B74siYZcPF8TnCdGI1l9rpPvg",
    "previous_cursor": "ARhwnmi1hA7wEbHbMjdYQlOB_ZusP4fYvw",
    "total_count": 125
  }
}
```

## Domain Types

### API Key

- `APIKey`

  API Key response.

  - `id: string`

    API Key ID.

  - `created_at: string`

    When the API Key was created.

  - `expires_at: string`

    When the API Key expires and is no longer valid.

  - `managed: boolean`

    Whether this API key is system-managed.

  - `name: string`

    API Key name.

  - `permissions: Array<APIKeyPermission>`

    Scoped permissions for this API key.

    - `permission: APIPermissionLevel`

      Permission level: "read" or "edit".

      - `"read"`

      - `"edit"`

    - `resource_type: APIPermissionResourceType`

      Resource type this permission applies to.

      - `"vm"`

      - `"vpc"`

      - `"volume"`

      - `"connect_connection"`

      - `"rpc_node_dedicated"`

      - `"rpc_node_flex"`

      - `"nks_cluster"`

      - `"nks_node_pool"`

      - `"project"`

      - `"api_key"`

      - `"organization"`

      - `"audit_log"`

      - `"usage"`

  - `project_ids: Array<string>`

    Project IDs this API key is scoped to.

  - `source_ip_rule: SourceIPRuleResponse`

    IP filter rules.

    - `allowed: Array<string>`

      List of IPv4 CIDR addresses to allow.

    - `blocked: Array<string>`

      List of IPv4 CIDR addresses to deny.

  - `status: "active" | "inactive" | "expired"`

    Status of the API Key.

    - `"active"`

    - `"inactive"`

    - `"expired"`

  - `tags: Array<string>`

    Tags to attach to the API Key.

  - `updated_at: string`

    When the API Key was updated.

  - `key?: string`

    API Key. Only returned on creation.

  - `starts_at?: string`

    When the API Key starts to be valid.

### API Key List

- `APIKeyList`

  - `items: Array<APIKey>`

    - `id: string`

      API Key ID.

    - `created_at: string`

      When the API Key was created.

    - `expires_at: string`

      When the API Key expires and is no longer valid.

    - `managed: boolean`

      Whether this API key is system-managed.

    - `name: string`

      API Key name.

    - `permissions: Array<APIKeyPermission>`

      Scoped permissions for this API key.

      - `permission: APIPermissionLevel`

        Permission level: "read" or "edit".

        - `"read"`

        - `"edit"`

      - `resource_type: APIPermissionResourceType`

        Resource type this permission applies to.

        - `"vm"`

        - `"vpc"`

        - `"volume"`

        - `"connect_connection"`

        - `"rpc_node_dedicated"`

        - `"rpc_node_flex"`

        - `"nks_cluster"`

        - `"nks_node_pool"`

        - `"project"`

        - `"api_key"`

        - `"organization"`

        - `"audit_log"`

        - `"usage"`

    - `project_ids: Array<string>`

      Project IDs this API key is scoped to.

    - `source_ip_rule: SourceIPRuleResponse`

      IP filter rules.

      - `allowed: Array<string>`

        List of IPv4 CIDR addresses to allow.

      - `blocked: Array<string>`

        List of IPv4 CIDR addresses to deny.

    - `status: "active" | "inactive" | "expired"`

      Status of the API Key.

      - `"active"`

      - `"inactive"`

      - `"expired"`

    - `tags: Array<string>`

      Tags to attach to the API Key.

    - `updated_at: string`

      When the API Key was updated.

    - `key?: string`

      API Key. Only returned on creation.

    - `starts_at?: string`

      When the API Key starts to be valid.

  - `pagination: Pagination`

    Pagination response details.

    - `next_cursor: string | null`

    - `previous_cursor: string | null`

    - `total_count: number`

### API Key Permission

- `APIKeyPermission`

  API Key permission.

  - `permission: APIPermissionLevel`

    Permission level: "read" or "edit".

    - `"read"`

    - `"edit"`

  - `resource_type: APIPermissionResourceType`

    Resource type this permission applies to.

    - `"vm"`

    - `"vpc"`

    - `"volume"`

    - `"connect_connection"`

    - `"rpc_node_dedicated"`

    - `"rpc_node_flex"`

    - `"nks_cluster"`

    - `"nks_node_pool"`

    - `"project"`

    - `"api_key"`

    - `"organization"`

    - `"audit_log"`

    - `"usage"`

### API Permission Level

- `APIPermissionLevel = "read" | "edit"`

  Permission level: "read" or "edit".

  - `"read"`

  - `"edit"`

### API Permission Resource Type

- `APIPermissionResourceType = "vm" | "vpc" | "volume" | 10 more`

  Resource type this permission applies to.

  - `"vm"`

  - `"vpc"`

  - `"volume"`

  - `"connect_connection"`

  - `"rpc_node_dedicated"`

  - `"rpc_node_flex"`

  - `"nks_cluster"`

  - `"nks_node_pool"`

  - `"project"`

  - `"api_key"`

  - `"organization"`

  - `"audit_log"`

  - `"usage"`
