Skip to main content
Cohere

Search documentation

Type to search this documentation.

Tokenize

POST/v1/tokenizeTokenize

This endpoint splits input text into smaller units called tokens using byte-pair encoding (BPE). To learn more about tokenization and byte pair encoding, see the tokens page.

Parameters

X-Client-Namestringheader

The name of the project that is making the request.

Request body

application/json
object
modelstringrequired

The input will be tokenized by the tokenizer that is used by this model.

textstringrequired

The string to be tokenized, the minimum text length is 1 character, and the maximum text length is 65536 characters.

maxLength 65536 · minLength 1

Example request
{
  "model": "command",
  "text": "tokenize me! :D"
}

Responses

200OKapplication/json

Headers

X-API-Warning

The name of the project that is making the request.

object
metaobject
Show child attributes
api_versionobject
Show child attributes
is_deprecatedboolean
is_experimentalboolean
versionstringrequired
billed_unitsobject
Show child attributes
classificationsnumber

The number of billed classifications units.

image_tokensnumber

The number of billed image tokens.

imagesnumber

The number of billed images.

input_tokensnumber

The number of billed input tokens.

output_tokensnumber

The number of billed output tokens.

pagesnumber

The number of billed pages parsed.

search_unitsnumber

The number of billed search units.

cached_tokensnumber

The number of prompt tokens that hit the inference cache.

tokensobject
Show child attributes
input_tokensnumber

The number of tokens used as input to the model.

output_tokensnumber

The number of tokens produced by the model.

warningsarray of string
Show child attributes
token_stringsarray of stringrequired
Show child attributes
tokensarray of integerrequired

An array of tokens, where each token is an integer.

Show child attributes
Example response
{
  "meta": {
    "api_version": {
      "version": "1"
    }
  },
  "token_strings": [
    "token",
    "ize'",
    " me",
    "!",
    " :",
    "D"
  ],
  "tokens": [
    34160,
    974,
    514,
    34,
    1420,
    69
  ]
}
400This error is returned when the request is not well formed. This could be because: - JSON is invalid - The request is missing required fields - The request contains an invalid combination of fields application/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
401This error indicates that the operation attempted to be performed is not allowed. This could be because: - The api token is invalid - The user does not have the necessary permissions application/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
403This error indicates that the operation attempted to be performed is not allowed. This could be because: - The api token is invalid - The user does not have the necessary permissions application/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
404This error is returned when a resource is not found. This could be because: - The endpoint does not exist - The resource does not exist eg model id, dataset id application/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
422This error is returned when the request is not well formed. This could be because: - JSON is invalid - The request is missing required fields - The request contains an invalid combination of fields application/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
429Too many requestsapplication/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
498This error is returned when a request or response contains a deny-listed token. application/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
499This error is returned when a request is cancelled by the user. application/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
500This error is returned when an uncategorised internal server error occurs. application/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
501This error is returned when the requested feature is not implemented. application/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
503This error is returned when the service is unavailable. This could be due to: - Too many users trying to access the service at the same time application/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
504This error is returned when a request to the server times out. This could be due to: - An internal services taking too long to respond application/json
object
idstring
messagestring
Example response
{
  "id": "string",
  "message": "string"
}
Documentation menu