> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# create

> Create a room token that a participant uses to connect to a video room.

Create a room token that a participant uses to connect to a video room. The token
encodes the room name, user identity, and granted permissions.

### Schema

```yaml
openapi: 3.1.0
info:
  title: API
  version: 1.0.0
paths:
  /api/video/room_tokens:
    post:
      operationId: subpackageRoomTokens_create_room_token
      summary: Create room token
      description: >-
        Creates a Room Token that a client consumes to join a named Video Room
        with the supplied identity, permissions, join window, and media
        settings. Call this operation from your server when granting a user
        access to an SDK-based room; never expose the project API token used to
        create it. Managed Video Conferences use their own [Conference
        Tokens](/docs/apis/rest/video/conference-tokens/list-conference-tokens).


        #### Permissions


        The API token used to authenticate must have the following scope(s)
        enabled to make a successful request: _Video_.


        [Learn more about API scopes](/docs/platform/your-signalwire-api-space).
      tags:
        - subpackage_roomTokens
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Video.RoomTokenResponse'
        '400':
          description: The request is invalid.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Types.StatusCodes.StatusCode400'
        '401':
          description: Access is unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Types.StatusCodes.StatusCode401'
        '422':
          description: The request contains invalid parameters. See errors for details.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Video.VideoStatusCode422'
        '500':
          description: An internal server error occurred.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Types.StatusCodes.StatusCode500'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Video.CreateRoomTokenRequest'
tags:
  - name: subpackage_roomTokens
servers:
  - url: https://%7BYour_Space_Name%7D.signalwire.com
    description: SignalWire API
components:
  schemas:
    Video.RoomTokenPermission:
      type: string
      enum:
        - room.member.audio_mute
        - room.member.audio_unmute
        - room.member.video_mute
        - room.member.video_unmute
        - room.member.deaf
        - room.member.undeaf
        - room.member.set_input_volume
        - room.member.set_output_volume
        - room.member.set_input_sensitivity
        - room.member.set_position
        - room.member.set_meta
        - room.member.raisehand
        - room.member.lowerhand
        - room.member.remove
        - room.member.promote
        - room.member.demote
        - room.hide_video_muted
        - room.list_available_layouts
        - room.lock
        - room.playback
        - room.playback_seek
        - room.prioritize_handraise
        - room.recording
        - room.set_layout
        - room.set_position
        - room.set_meta
        - room.show_video_muted
        - room.stream
        - room.unlock
        - room.self.audio_mute
        - room.self.audio_unmute
        - room.self.video_mute
        - room.self.video_unmute
        - room.self.deaf
        - room.self.undeaf
        - room.self.set_input_volume
        - room.self.set_output_volume
        - room.self.set_input_sensitivity
        - room.self.set_position
        - room.self.set_meta
        - room.self.raisehand
        - room.self.lowerhand
        - room.self.screenshare
        - room.self.additional_source
      description: Valid permission scopes for room tokens.
      title: Video.RoomTokenPermission
    Video.JoinAsType:
      type: string
      enum:
        - audience
        - member
      description: Join as type for room tokens.
      title: Video.JoinAsType
    Video.MediaAllowedType:
      type: string
      enum:
        - all
        - video-only
        - audio-only
      description: Media allowed type for room tokens.
      title: Video.MediaAllowedType
    VideoCreateRoomTokenRequestRoomMeta:
      type: object
      properties: {}
      description: Set the room meta. Maximum of 2000 characters when serialized to JSON.
      title: VideoCreateRoomTokenRequestRoomMeta
    VideoCreateRoomTokenRequestMeta:
      type: object
      properties: {}
      description: Set the member meta. Maximum of 2000 characters when serialized to JSON.
      title: VideoCreateRoomTokenRequestMeta
    Video.CreateRoomTokenRequest:
      type: object
      properties:
        room_name:
          type: string
          pattern: ^[A-Za-z0-9_-]+$
          maxLength: 100
          description: >-
            Room's unique named identifier. Allowed characters: A-Za-z0-9_-. Up
            to 100 characters. The room does not have to exist when the token is
            created, but must exist prior to joining, or ensure auto_create_room
            is set to true.
        user_name:
          type: string
          maxLength: 100
          description: >-
            A display name to use for the user. Up to 100 characters. (If not
            supplied, a random alphanumeric string will be returned for each
            authorization with this token.)
        permissions:
          type: array
          items:
            $ref: '#/components/schemas/Video.RoomTokenPermission'
          default:
            - room.self.audio_mute
            - room.self.audio_unmute
            - room.self.video_mute
            - room.self.video_unmute
            - room.self.deaf
            - room.self.undeaf
            - room.self.set_input_volume
            - room.self.set_output_volume
            - room.self.set_input_sensitivity
            - room.self.screenshare
            - room.self.additional_source
          description: >-
            A list of permissions, which define what user can do once they join
            the room. If `join_as` is `audience`, permissions are set to an
            empty array regardless of the value provided.
        join_from:
          type: string
          format: date-time
          description: >-
            The user can't join the room before this time. Expects RFC 3339
            datetime: `2022-01-01T23:59:60Z`. Date only: `2022-01-01` will be
            converted to `2022-01-01T00:00:00Z`
        join_until:
          type: string
          format: date-time
          description: >-
            The user can't join the room after this time. Expects RFC 3339
            datetime: `2022-01-01T23:59:60Z`. Date only: `2022-01-01` will be
            converted to `2022-01-01T00:00:00Z`
        remove_at:
          type: string
          format: date-time
          description: >-
            Remove user from the room at this time. Expects RFC 3339 datetime:
            `2022-01-01T23:59:60Z`. Date only: `2022-01-01` will be converted to
            `2022-01-01T00:00:00Z`
        remove_after_seconds_elapsed:
          type: integer
          maximum: 200000
          exclusiveMinimum: 0
          description: Remove user after they are in the room for N seconds.
        join_audio_muted:
          type: boolean
          default: false
          description: Whether the user joins the room with their audio muted.
        join_video_muted:
          type: boolean
          default: false
          description: Whether the user joins the room with their video muted.
        auto_create_room:
          type: boolean
          default: true
          description: >-
            By default, if the user tries to use this token to join a room that
            doesn't exist, it will be created with default configuration. Set
            this to false to require the room to exist beforehand.
        enable_room_previews:
          type: boolean
          default: false
          description: >-
            Whether to generate a video with a preview of the content of the
            room. This parameter has effect only if this token auto-creates the
            room, thus it will be ignored if the room already exists.
        room_display_name:
          type: string
          maxLength: 200
          description: >-
            Display name used if a room is auto-created when the token joins.
            Maximum of 200 characters. Defaults to the value of room_name.
        end_room_session_on_leave:
          type: boolean
          default: false
          description: >-
            Whether to end the room session when the member using this token
            leaves the room.
        join_as:
          $ref: '#/components/schemas/Video.JoinAsType'
          default: member
          description: >-
            Whether the user should join as a member or as a non-interactive
            audience participant. Audience participants cannot send audio or
            video.
        media_allowed:
          $ref: '#/components/schemas/Video.MediaAllowedType'
          default: all
          description: Indicates what media the user is allowed to receive.
        room_meta:
          $ref: '#/components/schemas/VideoCreateRoomTokenRequestRoomMeta'
          description: >-
            Set the room meta. Maximum of 2000 characters when serialized to
            JSON.
        meta:
          $ref: '#/components/schemas/VideoCreateRoomTokenRequestMeta'
          description: >-
            Set the member meta. Maximum of 2000 characters when serialized to
            JSON.
        sync_audio_video:
          type: boolean
          default: false
          description: Enable/disable jitter buffer audio-video sync.
      required:
        - room_name
      description: Request body for creating a room token.
      title: Video.CreateRoomTokenRequest
    Video.RoomTokenResponse:
      type: object
      properties:
        token:
          type: string
          description: A Room Token to be used by clients to connect to the Room.
      required:
        - token
      description: Room token response object.
      title: Video.RoomTokenResponse
    TypesStatusCodesStatusCode400Error:
      type: string
      enum:
        - Bad Request
      title: TypesStatusCodesStatusCode400Error
    Types.StatusCodes.StatusCode400:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/TypesStatusCodesStatusCode400Error'
      required:
        - error
      description: The request is invalid.
      title: Types.StatusCodes.StatusCode400
    TypesStatusCodesStatusCode401Error:
      type: string
      enum:
        - Unauthorized
      title: TypesStatusCodesStatusCode401Error
    Types.StatusCodes.StatusCode401:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/TypesStatusCodesStatusCode401Error'
      required:
        - error
      description: Access is unauthorized.
      title: Types.StatusCodes.StatusCode401
    Types.StatusCodes.RestApiErrorItem:
      type: object
      properties:
        type:
          type: string
          description: The category of error.
        code:
          type: string
          description: A specific error code.
        message:
          type: string
          description: A description of what caused the error.
        attribute:
          type:
            - string
            - 'null'
          description: The request parameter that caused the error, if applicable.
        url:
          type: string
          description: A link to documentation about this error.
      required:
        - type
        - code
        - message
        - url
      description: Details about a specific error.
      title: Types.StatusCodes.RestApiErrorItem
    Video.VideoStatusCode422:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/Types.StatusCodes.RestApiErrorItem'
          description: List of validation errors.
      required:
        - errors
      description: The request contains invalid parameters. See errors for details.
      title: Video.VideoStatusCode422
    TypesStatusCodesStatusCode500Error:
      type: string
      enum:
        - Internal Server Error
      title: TypesStatusCodesStatusCode500Error
    Types.StatusCodes.StatusCode500:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/TypesStatusCodesStatusCode500Error'
      required:
        - error
      description: An internal server error occurred.
      title: Types.StatusCodes.StatusCode500

```

## **Response Example**

### Response (200)

```json
{
  "token": "eyJ0eXAiOiJWUlQiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2MjIxMjAxMjMsImp0aSI6ImRmMzFjYTQ4LWRiZGMtNGJjZi1hYWU2LTQ1NWEwOGM5NDg2YSIsInN1YiI6IjBjOTdmNjM1LTFjMTMtNGZjMS04NmY3LWJiMmJlODU5ZDhiOSIsInUiOiJKb2huIERvZSIsInIiOiJteV9zdXBlcl9hd2Vzb21lX3Jvb20iLCJzIjpbInJvb20uc2VsZi5hdWRpb191bm11dGUiXSwiYWNyIjp0cnVlLCJqZiI6MTYyMDg5NjQwMCwianUiOjE2MjA5MDU5NjgsInJhdCI6MTYyMDkwMDAwMCwicnNlIjo5MDB9.5mu_H2PjQLtNBbMsBlS0c91EgsDjJzvZUFgj5-tP4VA0VoHZPIGgV_DLRGKt-BqG-DqC5LhpsdMWEFjhVkTBpQ"
}
```

## **Example**

```python {9}
from signalwire.rest import RestClient

client = RestClient(
    project="your-project-id",
    token="your-api-token",
    host="your-space.signalwire.com",
)

token = client.video.room_tokens.create(
    room_name="standup",
    user_name="Alice",
    permissions=[
        "room.self.audio_mute",
        "room.self.audio_unmute",
        "room.self.video_mute",
        "room.self.video_unmute",
    ]
)
print(token["token"])  # JWT string for the client SDK
```