Skip to content
ACS Infra
Tokenize

Tokenize

POST
/v1/tokenize

vLLM: turn a text into the model's token ids with the tokenizer that POST /v1/completions counts with, and count them. With return_token_strs, also each token's text. The API asks no Inference, so the route costs no tokens and never starts a GPU.

Authorization

bearer
headerAuthorizationBearer <token>

An API key: Authorization: Bearer sk-acs-..., or a key of the old platform, acs-bm-.... A User makes and revokes keys in the App.

Request Body

application/json
  1. body
model?string

The Base model whose tokenizer to use: an id from GET /v1/models, such as llama-8b. Left out, the model that GET /v1/models marks default.

Match^[^\u0000]*$
prompt*string

vLLM: the text to tokenize, at most 65536 bytes as UTF-8.

Match^[^\u0000]*$
add_special_tokens?boolean

vLLM: add the model's special tokens, such as BOS, as POST /v1/completions does with the same field.

return_token_strs?boolean

vLLM: also return each token's text in token_strs, as a Completion's tokens and top_logprobs show it.

Response Body

TokenizeResponse

application/json
  1. response
count*integer

The number of tokens: the count that POST /v1/completions holds for this prompt.

max_model_len*integer

The model's context: its prompt and generated tokens together.

tokens*array<integer>

The token ids, in order.

token_strs*array<string>|

With return_token_strs, the text of each token, the way a Completion's tokens and top_logprobs keys show it. A token that holds part of a character's UTF-8 bytes reads �. Otherwise null.

Example Request
curl -X POST 'https://api.staging.infra.acsresearch.org/v1/tokenize' \  -H 'Authorization: Bearer <API_KEY>' \  -H 'Content-Type: application/json' \  -d '{  "prompt": "string"}'
Example Response
{  "count": 0,  "max_model_len": 0,  "tokens": [    0  ],  "token_strs": [    "string"  ]}