/v1beta/models/{model}:countTokensCount tokens (Gemini)
Estimates input tokens with the gateway's own tokenizer. Free and never billed; an estimate, not the provider's count.
認証: AuthorizationヘッダーにBearer形式のAPIキー
パスパラメータ
modelstring必須A model slug.
リクエストボディ
contentsarray<object>必須Turns of
parts: text,inlineData, publicfileDataURLs,functionCall,functionResponse.systemInstructionobjecttoolsarray<object>functionDeclarationsonly; Google server tools are refused.toolConfigobjectgenerationConfigobjectSampling,
maxOutputTokens,stopSequences,responseSchemaorresponseJsonSchema,thinkingConfig.providerobjectOpenRouter's routing-preference object, resolved against the model's own provider routes. Only tightens, never loosens, your organization's policy.
provider
zdrbooleantrueserves only zero-data-retention routes for this request, or refuses with a 403 naming the excluded providers.onlyarray<string>Keep only these providers.
ignorearray<string>Drop these providers.
orderarray<string>Try these providers first, in order; the rest stay as fallbacks.
allow_fallbacksbooleanfalsewithorderserves only the listed providers; withoutorder, only the first eligible route.
レスポンス
200The estimate.
レスポンス
totalTokensintegerx-experiential-ignored-parametersarray<string>
400Invalid request, in the Google envelope.
レスポンス
errorobjecterror
codeintegerThe HTTP status.
messagestringstatusstringFor example
INVALID_ARGUMENT,UNAUTHENTICATED,RESOURCE_EXHAUSTED.detailsarray<object>
401The key is missing or invalid.
レスポンス
errorobjecterror
codeintegerThe HTTP status.
messagestringstatusstringFor example
INVALID_ARGUMENT,UNAUTHENTICATED,RESOURCE_EXHAUSTED.detailsarray<object>
リクエスト
curl https://api.experientiallabs.ai/v1beta/models/gpt-6-luna:countTokens \
-H "x-goog-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"contents": [{"role": "user", "parts": [{"text": "Say hi."}]}]}'
レスポンス
{
"totalTokens": 3,
"x-experiential-ignored-parameters": [
"input_tokens->estimated(gateway_tokenizer)"
]
}https://api.experientiallabs.ai/v1beta/models/gpt-6-luna:countTokens