Runs a model's tokenizer on a text and returns the token count.
HTTP request
POST https://generativelanguage.googleapis.com/v1beta3/{model=models/*}:countTextTokens
The URL uses gRPC Transcoding syntax.
Path parameters
Parameters | |
---|---|
model |
Required. The model's resource name. This serves as an ID for the Model to use. This name should match a model name returned by the Format: |
Request body
The request body contains data with the following structure:
JSON representation |
---|
{
"prompt": {
object ( |
Fields | |
---|---|
prompt |
Required. The free-form input text given to the model as a prompt. |
Response body
A response from models.countTextTokens
.
It returns the model's tokenCount
for the prompt
.
If successful, the response body contains data with the following structure:
JSON representation |
---|
{ "tokenCount": integer } |
Fields | |
---|---|
tokenCount |
The number of tokens that the Always non-negative. |
Authorization scopes
Requires the following OAuth scope:
https://www.googleapis.com/auth/generative-language
For more information, see the Authentication Overview.