> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gengen.farm/llms.txt
> Use this file to discover all available pages before exploring further.

# Count input tokens

> Count Gemini 4 Neon or Hydrogen input tokens before generation without a wallet charge.

`POST /v1/token-counts` requires an active GENGEN API key and does not require
wallet balance. It creates no generation, wallet hold, or charge.

```bash theme={"dark"}
curl https://gengen.farm/v1/token-counts \
  -H "Authorization: Bearer $GENGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gemini-4-hydrogen","input":"Explain idempotency in two sentences."}'
```

```json theme={"dark"}
{"model":"gemini-4-hydrogen","totalTokens":12}
```

The example count is illustrative; use the count returned for your request.
`cachedContentTokenCount` is included when supplied by the provider.

Supply **either** Chat Completions `messages` **or** Responses `input`, with the
same system instructions, content parts, function declarations and
`providerOptions.google` that you plan to generate with. Multimodal content and
tool-history validation match the generation endpoints. Maximum request body: 16 MiB.
Raw `gs://` media references, streaming, background execution and stored response
continuation are not supported.

Counts cover the supplied input. They do not predict generated output, the number
of Google searches, or content retrieved by Search and URL Context, so they are
not a final price quote. Generation is settled using its returned usage.

Try **Count tokens · Free** in the
[Hydrogen text Explorer](https://gengen.farm/api-explorer/demos/text-generation?model=gemini-4-hydrogen).


## OpenAPI

````yaml openapi/google.yaml POST /token-counts
openapi: 3.1.0
info:
  title: Google models API
  version: 1.0.0
  description: Generate text and images with Gemini through the GENGEN API.
servers:
  - url: https://gengen.farm/api/gengen/v1
    description: Production
security:
  - bearerAuth: []
paths:
  /token-counts:
    post:
      summary: Count Gemini input tokens
      description: >-
        Count Neon or Hydrogen input tokens without generation or a wallet
        charge. Requires an active API key, but no wallet balance. Supply
        exactly one of messages or input, using the same content parts and tool
        declarations as generation. Counts exclude future search/URL retrieval
        and generated output.
      operationId: countGoogleTokens
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GoogleTokenCountRequest'
            example:
              model: gemini-4-hydrogen
              input: Explain idempotency in two sentences.
      responses:
        '200':
          description: >-
            The provider-reported input token count. No wallet hold or charge is
            created.
          content:
            application/json:
              schema:
                type: object
                required:
                  - model
                  - totalTokens
                properties:
                  model:
                    type: string
                    enum:
                      - gemini-4-neon
                      - gemini-4-hydrogen
                  totalTokens:
                    type: integer
                    minimum: 0
                  cachedContentTokenCount:
                    type: integer
                    minimum: 0
        default:
          $ref: '#/components/responses/Error'
components:
  schemas:
    GoogleTokenCountRequest:
      type: object
      required:
        - model
      oneOf:
        - required:
            - messages
          not:
            required:
              - input
        - required:
            - input
          not:
            required:
              - messages
      properties:
        model:
          type: string
          enum:
            - gemini-4-neon
            - gemini-4-hydrogen
        messages: 2c9fc302-0590-4a25-8c81-53f5aaa7fc2a
        input: 3df06360-f7b5-417f-ac7f-951c8dbae471
        instructions:
          type: string
        tools:
          type: array
          items:
            type: object
            additionalProperties: true
        providerOptions:
          $ref: '#/components/schemas/GoogleProviderOptions'
        stream:
          type: boolean
          const: false
      description: >-
        Uses the same validation and native conversation replay as generation.
        Only synchronous, full-history requests are accepted. Maximum request
        body is 16 MiB.
    GoogleProviderOptions:
      type: object
      properties:
        google:
          type: object
          properties:
            tools:
              type: array
              description: >-
                Native Google tools. Each entry defines functionDeclarations,
                codeExecution, computerUse, or (Hydrogen and Neon only)
                googleSearch or urlContext. Search and URL Context accept empty
                objects only. Use Search separately from other built-in tools
                and AGENTIC video so their different input billing can be
                measured. User-defined functions can coexist with Search.
              items:
                type: object
                additionalProperties: true
              examples:
                - - codeExecution: {}
                - - computerUse:
                      environment: ENVIRONMENT_BROWSER
                - - googleSearch: {}
                - - urlContext: {}
            toolConfig:
              type: object
              additionalProperties: true
              description: >-
                Google ToolConfig. Normalized tool_choice takes precedence.
                streamFunctionCallArguments=true is rejected; SSE emits complete
                call arguments.
            thinkingLevel:
              type: string
              enum:
                - MINIMAL
                - LOW
                - MEDIUM
                - HIGH
                - XHIGH
              description: >-
                Provider-native alias for `reasoning_effort`. MINIMAL is
                supported only by Gemini 3.5 Flash-Lite; XHIGH is supported by
                Hydrogen and Neon, which default to HIGH.
            generationConfig:
              type: object
              description: >-
                Advanced generation options. Hydrogen and Neon thinkingConfig
                accepts thinkingLevel (LOW, MEDIUM, HIGH, XHIGH) and
                prefixMismatchBehavior (ERROR by default, or DROP for edited or
                compacted history). Explicit caches and continuation tokens are
                not supported.
              properties:
                thinkingConfig:
                  type: object
                  properties:
                    thinkingLevel:
                      type: string
                      enum:
                        - MINIMAL
                        - LOW
                        - MEDIUM
                        - HIGH
                        - XHIGH
                      description: >-
                        Model-specific thinking level. Hydrogen and Neon accept
                        LOW, MEDIUM, HIGH (default), or XHIGH.
                    prefixMismatchBehavior:
                      type: string
                      enum:
                        - ERROR
                        - DROP
                      description: >-
                        Hydrogen and Neon only. ERROR is the default; DROP
                        discards mismatched signatures after earlier history is
                        edited or compacted.
                mediaResolution:
                  type: string
                  enum:
                    - MEDIA_RESOLUTION_LOW
                    - MEDIA_RESOLUTION_MEDIUM
                    - MEDIA_RESOLUTION_HIGH
                responseLogprobs:
                  type: boolean
                logprobs:
                  type: integer
                  minimum: 1
                  maximum: 20
            safetySettings:
              type: array
              description: Optional content safety settings.
              items:
                type: object
                additionalProperties: true
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
  responses:
    Error:
      description: The request could not be completed.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: GENGEN API key
      description: A workspace API key beginning with `gengen_live_`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.