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

# Create Token with API key

> Creates user session for a user using an API key

<Warning>
  You can't use the QB token in this request. It will be ignored if you pass the QB-Token header in the request.
</Warning>

#### Path Parameters

<ParamField path="user_id" type="integer" required> ID of the user. Generated automatically by the server after user creation.</ParamField>

#### Headers

<ParamField header="Authorization" type="string" required default="ApiKey {your_api_key}"> API key from Dashboard. Expected format: `ApiKey {your_api_key}`. Must be used either QB-Token or Authorization.</ParamField>

#### Responses

<AccordionGroup>
  <Accordion title="201">
    A successful response

    <ResponseField name="token" type="string" />

    <ResponseField name="expires_at" type="string" />
  </Accordion>

  <Accordion title="401">
    An error response

    <ResponseField name="errors" type="object">
      <Expandable title="properties">
        <ResponseField name="base" type="array of strings" />
      </Expandable>
    </ResponseField>
  </Accordion>

  <Accordion title="404">
    An error response

    <ResponseField name="errors" type="object">
      <Expandable title="properties">
        <ResponseField name="base" type="array of strings" />
      </Expandable>
    </ResponseField>
  </Accordion>
</AccordionGroup>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST \
  -H "Authorization: ApiKey cf5709d6013fdb7a6787fbeb8340afed8aec4c69" \
  https://api.quickblox.com/users/123/tokens
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "token": "c56f382b402fb482086db956064592d3cd012bba",
    "expires_at": "2023-09-01T14:55:56Z"
  }
  ```

  ```json 401 theme={null}
  // Invalid Authorization header
  {
    "errors": {
      "base": [
        "Authorization header is invalid."
      ]
    }
  }

  // Invalid API Key
  {
    "errors": {
      "base": [
        "Api Key is not found."
      ]
    }
  }
  ```

  ```json 404  theme={null}
  {
    "errors": {
      "base": [
        "User is not found."
      ]
    }
  }
  ```
</ResponseExample>
