Skip to content
Docs

Create API Key

client.apiKeys.create(APIKeyCreateParams { expires_at, name, permissions, 4 more } body, RequestOptionsoptions?): APIKey { id, created_at, expires_at, 10 more }
POST/v1/api_keys

Create a new API key

ParametersExpand Collapse
body: APIKeyCreateParams { expires_at, name, permissions, 4 more }
expires_at: string

When the API Key expires and is no longer valid.

formatdate-time
name: string

API Key name.

maxLength255
minLength1
permissions: Array<Permission>

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

permission: APIPermissionLevel

Permission level: “read” or “edit”.

One of the following:
"read"
"edit"

Resource type this permission applies to.

One of the following:
"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 { allowed, blocked }

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.

formatdate-time
tags?: Array<string>

Tags to attach to the API Key.

ReturnsExpand Collapse
APIKey { id, created_at, expires_at, 10 more }

API Key response.

id: string

API Key ID.

created_at: string

When the API Key was created.

formatdate-time
expires_at: string

When the API Key expires and is no longer valid.

formatdate-time
managed: boolean

Whether this API key is system-managed.

name: string

API Key name.

maxLength255
minLength1
permissions: Array<APIKeyPermission { permission, resource_type } >

Scoped permissions for this API key.

permission: APIPermissionLevel

Permission level: “read” or “edit”.

One of the following:
"read"
"edit"

Resource type this permission applies to.

One of the following:
"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 { allowed, blocked }

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.

One of the following:
"active"
"inactive"
"expired"
tags: Array<string>

Tags to attach to the API Key.

updated_at: string

When the API Key was updated.

formatdate-time
key?: string

API Key. Only returned on creation.

starts_at?: string

When the API Key starts to be valid.

formatdate-time

Create API Key

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);
{
  "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"
}
Returns Examples
{
  "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"
}