# Generate Access Token — LiveKit

> Generate an access token for a participant to join a LiveKit room. See the documentation.

- Key: `livekit-generate-access-token`
- Type: Action (Write)
- Version: 0.0.2
- App: LiveKit (`livekit`) — https://pipedream.com/apps/livekit.md
- This page (HTML): https://pipedream.com/apps/livekit/actions/generate-access-token
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/livekit/actions/generate-access-token/generate-access-token.mjs

## Description

Generate an access token for a participant to join a LiveKit room. [See the documentation](https://github.com/livekit/node-sdks/tree/main/packages/livekit-server-sdk).

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `room` | `string` | No | The name of the room to join Options are loaded from the connected account. |
| `ttl` | `integer` | No | How long the access token should be valid for (in seconds) |
| `name` | `string` | No | Display name for the participant |
| `identity` | `string` | Yes | Unique identity for the participant joining the call |
| `metadata` | `string` | No | Optional metadata to attach to the participant |
| `canPublish` | `boolean` | No | Whether the participant can publish audio/video tracks |
| `canSubscribe` | `boolean` | No | Whether the participant can subscribe to other participants' tracks |
| `canPublishData` | `boolean` | No | Whether the participant can publish data messages |
| `hidden` | `boolean` | No | Whether the participant should be hidden from other participants |
| `roomCreate` | `boolean` | No | Permission to create rooms |
| `roomList` | `boolean` | No | Permission to list rooms |
| `roomRecord` | `boolean` | No | Permission to start a recording |
| `roomAdmin` | `boolean` | No | Permission to control the specific room |
| `ingressAdmin` | `boolean` | No | Permission to control ingress, not specific to any room or ingress |
| `canUpdateOwnMetadata` | `boolean` | No | Allow participant to update its own metadata |
| `recorder` | `boolean` | No | Participant is recording the room, allows room to indicate it's being recorded |
| `agent` | `boolean` | No | Participant allowed to connect to LiveKit as Agent Framework worker |
| `canSubscribeMetrics` | `boolean` | No | Allow participant to subscribe to metrics |
| `destinationRoom` | `string` | No | Destination room which this participant can forward to |
| `createRoomIfNotExists` | `boolean` | No | Whether to create the room if it doesn't exist |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "livekit",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "livekit-generate-access-token",
  arguments: {
    room: "Room Name",
    ttl: 10,
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "livekit-generate-access-token",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    livekit: { authProvisionId: "apn_xxxxxxx" },
    room: "Room Name",
    ttl: 10,
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "livekit-generate-access-token",
    "configured_props": {
      "livekit": { "authProvisionId": "apn_xxxxxxx" },
      "room": "Room Name",
      "ttl": 10
    }
  }'
```

---

- App: https://pipedream.com/apps/livekit.md · All apps: https://pipedream.com/apps
