Gemini AI Studio icon

Gemini AI Studio

Use the Google Gemini API through direct AI Studio REST calls

Actions16

Token → Count Tokens

AI-generated

Summary

Count tokens for a specified Gemini AI Studio model input to estimate token usage before processing.

Inputs

  • Model (required) — Select the Gemini model to use for token counting; supports loading available models and arbitrary values.
  • Input Mode (required) — Choose the input format to count tokens for: Simple Text, Contents JSON, Generate Content Request JSON, or Raw Request JSON.
  • Text (required) — Enter simple text string to count tokens for when Input Mode is 'Simple Text'.
  • Contents (JSON) (required) — Provide Gemini contents array JSON for token counting when Input Mode is 'Contents JSON'.
  • Generate Content Request (JSON) (required) — Provide complete generateContentRequest JSON for counting tokens including system instructions or other config when Input Mode is 'Generate Content Request JSON'.
  • Raw Request Body (JSON) (required) — Provide complete raw request JSON sent to the :countTokens endpoint when Input Mode is 'Raw Request JSON'.

Output shape

a single item with a JSON object containing the token count response from Gemini API

The output JSON matches the Gemini :countTokens API response and is paired with the input item. Errors provide messages when the request fails.

Links

Discussion