---
title: "Count tokens (Gemini-compatible)"
method: POST
path: "/v1beta/models/{model}:countTokens"
tags: ["Gemini"]
---

# Count tokens (Gemini-compatible)

`POST /v1beta/models/{model}:countTokens`

## Request

- Base URL: `https://api.tokenlab.sh`
- URL: `https://api.tokenlab.sh/v1beta/models/{model}:countTokens`
- Auth: HTTP bearer

Counts tokens using the native Gemini CountTokens contract. Unknown fields and either official ProtoJSON field-name spelling are forwarded best-effort.

## Path parameters

- `model` string, required

## Query parameters

- `key` string

## Request body

- object
  - `contents` object[]
  - `generateContentRequest` object
  - `generate_content_request` object

## Response `200`

Gemini-native token count response

- object

## Other responses

- `400`: Gemini-native error response

---

[API](https://skmtc.dev/tokenlab/apis/tokenlab-ai-gateway.md) · [All operations](https://skmtc.dev/tokenlab/apis/tokenlab-ai-gateway/llms.txt) · [OpenAPI document](https://skmtc.dev/tokenlab/apis/tokenlab-ai-gateway/revisions/3208bfbcda22?raw)
