Skip to main content
POST
Count Tokens API

Authorizations

Authorization
string
header
required

API key authentication. Pass your API key as a Bearer token.

Headers

X-Opper-Name
string

Function name for tracing and project-level guardrail function-scope filtering.

X-Opper-Parent-Span-Id
string<uuid>

Parent span ID for distributed tracing context.

Path Parameters

model
string
required

Model id — a bare Gemini name (e.g. gemini-2.5-flash, resolved against the Gemini-direct provider) or an Opper-canonical id (e.g. vertexai/gemini-2.5-flash).

Body

application/json
contents
any
required

Any value

input
any
required

Any value

agent
string
background
boolean
cache_control
object

Opt in to automatic prompt caching for Anthropic-family models routed through this Gemini-shape endpoint: {"type":"ephemeral"} (optionally "ttl":"1h"). Places one moving cache breakpoint on the largest cacheable prefix. Caching is off unless set; no-op on Gemini and other providers with automatic server-side caching. Cache writes cost 1.25x input and reads 0.1x

custom_model_credentials
object
generation_config
object
metadata
object
model
string
previous_interaction_id
string
response_format
object
response_mime_type
string
safety_settings
object[]
store
boolean
stream
boolean
system_instruction
object
tool_config
object
tools
object[]

Response

Successful response

totalTokens
integer
required
cachedContentTokenCount
integer