countTokens method

Runs a model's tokenizer on input Content and returns the token count. Refer to the tokens guide to learn more about tokens.

Throws a http.ClientException if there were problems communicating with the API service. Throws a StatusException if the API failed with a Status message. Throws a ServiceException for any other failure.

Implementation

Future<CountTokensResponse> countTokens(CountTokensRequest request) async {
  final url = Uri.https(_host, '/v1beta/${request.model}:countTokens');
  final response = await _client.post(url, body: request);
  return CountTokensResponse.fromJson(response);
}