> 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. # createToken > Chat API namespace — token creation. Chat API namespace — token creation. ### Schema ```yaml openapi: 3.1.0 info: title: API version: 1.0.0 paths: /api/chat/tokens: post: operationId: subpackageChatTokens_create_chat_token summary: Create chat token description: >- Creates a time-limited Chat Token that a client consumes to access the Chat channels and permissions supplied in the request. Call this operation from your server when granting Chat access to a member; choose a lifetime from 1 minute through 30 days and never expose the project API token used to create it. Use [Create PubSub token](/docs/apis/rest/pubsub/create-token) for PubSub channels or [Create API token](/docs/apis/rest/project-tokens/create-token) for server-side REST authentication. #### Permissions The API token used to authenticate must have the following scope(s) enabled to make a successful request: _Chat_. [Learn more about API scopes](/docs/platform/your-signalwire-api-space). tags: - subpackage_chatTokens responses: '200': description: The request has succeeded. content: application/json: schema: $ref: '#/components/schemas/Chat.ChatToken' '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/Chat.ChatToken422Error' requestBody: content: application/json: schema: $ref: '#/components/schemas/Chat.NewChatToken' tags: - name: subpackage_chatTokens servers: - url: https://%7BYour_Space_Name%7D.signalwire.com description: SignalWire API components: schemas: Chat.ChatChannel: type: object properties: {} description: >- User-defined channel names. Each channel is an object with `read` and/or `write` properties. Max of 500 channels. Either `read`, `write`, or both are required inside each channel and default to `false`. Each channel name can be up to 250 characters. Channel names cannot start with the reserved prefix `sw_`. Must be valid JSON. title: Chat.ChatChannel Chat.ChatState: type: object properties: {} description: >- An arbitrary JSON object available to store stateful application information in. Must be valid JSON and have a maximum size of 2,000 characters. title: Chat.ChatState Chat.NewChatToken: type: object properties: ttl: type: integer minimum: 1 maximum: 43200 description: >- The maximum time, in minutes, that the access token will be valid for. Between 1 and 43,200 (30 days). channels: $ref: '#/components/schemas/Chat.ChatChannel' description: >- User-defined channel names with read/write permissions. Max of 500 channels. Channel names cannot start with the reserved prefix `sw_` and can be up to 250 characters. member_id: type: string maxLength: 250 description: >- The unique identifier of the member. Up to 250 characters. If not specified, a random UUID will be generated. state: $ref: '#/components/schemas/Chat.ChatState' default: {} description: >- An arbitrary JSON object available to store stateful application information in. Must be valid JSON and have a maximum size of 2,000 characters. required: - ttl - channels title: Chat.NewChatToken Chat.ChatToken: type: object properties: token: type: string description: The generated Chat Token. required: - token title: Chat.ChatToken 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 Chat.ChatToken422Error: 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: Chat.ChatToken422Error ``` ## **Response Example** ### Response (200) ```json { "token": "eyJ0eXAiOiJWUlQiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2MjIxMjAxMjMsI...wMCwicnNlIjo5MDB9-BqG-DqC5LhpsdMWEFjhVkTBpQ" } ``` ## **Example** ```typescript {4} import { RestClient } from "@signalwire/sdk"; const client = new RestClient(); const result = await client.chat.createToken({ channels: ['general'] }); console.log(result); ``` > Chat API namespace — token creation.