Count Gemini input tokens
curl --request POST \
--url https://gengen.farm/api/gengen/v1/token-counts \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gemini-4-hydrogen",
"input": "Explain idempotency in two sentences."
}
'import requests
url = "https://gengen.farm/api/gengen/v1/token-counts"
payload = {
"model": "gemini-4-hydrogen",
"input": "Explain idempotency in two sentences."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'gemini-4-hydrogen', input: 'Explain idempotency in two sentences.'})
};
fetch('https://gengen.farm/api/gengen/v1/token-counts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"model": "gemini-4-neon",
"totalTokens": 1,
"cachedContentTokenCount": 1
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}Tools
Count input tokens
Count Gemini 4 Neon or Hydrogen input tokens before generation without a wallet charge.
POST
/
token-counts
Count Gemini input tokens
curl --request POST \
--url https://gengen.farm/api/gengen/v1/token-counts \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gemini-4-hydrogen",
"input": "Explain idempotency in two sentences."
}
'import requests
url = "https://gengen.farm/api/gengen/v1/token-counts"
payload = {
"model": "gemini-4-hydrogen",
"input": "Explain idempotency in two sentences."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'gemini-4-hydrogen', input: 'Explain idempotency in two sentences.'})
};
fetch('https://gengen.farm/api/gengen/v1/token-counts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"model": "gemini-4-neon",
"totalTokens": 1,
"cachedContentTokenCount": 1
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}POST /v1/token-counts requires an active GENGEN API key and does not require
wallet balance. It creates no generation, wallet hold, or charge.
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."}'
{"model":"gemini-4-hydrogen","totalTokens":12}
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.Body
application/json
- Option 1
- Option 2
Uses the same validation and native conversation replay as generation. Only synchronous, full-history requests are accepted. Maximum request body is 16 MiB.