xAI

xAI Tokenize Text API

The Tokenize Text API from xAI — 1 operation(s) for tokenize text.

Operations 1

POST /v1/tokenize-text Tokenize text with the specified model #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/xai:xai-tokenize-text-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Discovery needs no key. Ratings and market analysis are Pro.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

xai-tokenize-text-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: xAI's REST Tokenize Text API
  description: REST API for xAI compatible with other providers.
  license:
    name: ''
  version: 1.0.0
tags:
- name: Tokenize Text
paths:
  /v1/tokenize-text:
    post:
      tags:
      - Tokenize Text
      summary: Tokenize text with the specified model
      operationId: handle_tokenize_text_request
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TokenizeRequest'
            example:
              text: Hello world!
              model: latest
        required: true
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenizeResponse'
              example:
                token_ids:
                - token_id: 13902
                  string_token: Hello
                  token_bytes:
                  - 72
                  - 101
                  - 108
                  - 108
                  - 111
                - token_id: 1749
                  string_token: ' world'
                  token_bytes:
                  - 32
                  - 119
                  - 111
                  - 114
                  - 108
                  - 100
                - token_id: 161
                  string_token: '!'
                  token_bytes:
                  - 33
        '400':
          description: Bad request. The request is invalid or an invalid API key is provided.
      security:
      - bearerAuth: []
components:
  schemas:
    TokenizeResponseToken:
      type: object
      required:
      - token_id
      - string_token
      - token_bytes
      properties:
        string_token:
          type: string
          description: The string of the token.
        token_bytes:
          type: array
          items:
            type: integer
            format: int32
            minimum: 0
          description: The bytes that constituted the token.
        token_id:
          type: integer
          format: int32
          description: The integer representation of the token for the model.
          minimum: 0
    TokenizeRequest:
      type: object
      properties:
        model:
          type: string
          description: The model to tokenize with.
        text:
          type: string
          description: The text content to be tokenized.
        user:
          type:
          - string
          - 'null'
          description: Optional user identifier.
    TokenizeResponse:
      type: object
      required:
      - token_ids
      properties:
        token_ids:
          type: array
          items:
            $ref: '#/components/schemas/TokenizeResponseToken'
          description: A list of tokens.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer