> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pinata.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# create

> `org:write`

Create an API key

## Usage

```typescript theme={null}
import { PinataSDK } from "pinata";

const pinata = new PinataSDK({
  pinataJwt: process.env.PINATA_JWT!,
  pinataGateway: "example-gateway.mypinata.cloud",
});

const key = await pinata.keys.create({
  keyName: "user 1",
  permissions: {
    resources:  [
      "org:files:read",
      "org:groups:read"
    ]
  },
  maxUses: 1,
});
```

## Returns

```typescript theme={null}
type KeyResponse = {
  JWT: string;
  pinata_api_key: string;
  pinata_api_secret: string;
};
```

## Parameters

### keyName

* Type: `string`

Name for the API key

```typescript {2} theme={null}
const key = await pinata.keys.create({
  keyName: "user 1",
  permissions: {
    admin: true,
  },
  maxUses: 1,
});
```

### maxUses (Optional)

* Type: `number`

Limit the number of uses a key is valid for

```typescript {6} theme={null}
const key = await pinata.keys.create({
  keyName: "user 1",
  permissions: {
    admin: true,
  },
  maxUses: 1,
});
```

### permissions

* Type: [KeyPermissions](../types#keypermissions)

#### admin (Optional)

* Type: `boolean`

Grants the key admin access to all endpoints

```typescript {4} theme={null}
const key = await pinata.keys.create({
  keyName: "user 1",
  permissions: {
    admin: true,
  }
});
```

#### resources (Optional)

* Type: `ResourcePermission[]`

```typescript theme={null}
export type ResourcePermission =
	| "org:read"
	| "org:write"
	| "org:files:read"
	| "org:files:write"
	| "org:groups:read"
	| "org:groups:write"
	| "org:gateways:read"
	| "org:gateways:write"
	| "org:analytics:read"
	| "org:analytics:write";
```

Scope the API key by ResourcePermission

```typescript {4-7} theme={null}
const key = await pinata.keys.create({
  keyName: "user 1",
  permissions: {
    resources: [
      "org:files:read",
      "org:groups:read",
    ]
  }
});
```

#### endpoints (Optional)

* Type [Endpoints](../types#endpoints)

```typescript {3-20} theme={null}
const key = await pinata.keys.create({
  keyName: "user 1",
  permissions: {
    endpoints: {
      data: {
        pinList: true,
        userPinnedDataTotal: false
      },
      pinning: {
        hashMetadata: true,
        hashPinPolicy: false,
        pinByHash: true,
        pinFileToIPFS: true,
        pinJSONToIPFS: true,
        pinJobs: false,
        unpin: false,
        userPinPolicy: false
      }
    }
  }
});
```
