pub struct CountInputTokensRequest {
pub model: Option<String>,
pub input: InputParam,
pub instructions: Option<String>,
pub tools: Option<Vec<Tool>>,
}Expand description
Request body for POST /v1/responses/input_tokens.
A subset of CreateResponse — only the fields that reach the rendered
prompt. This mirrors AnthropicCountTokensRequest, which is the same
subset-of-the-create-request shape for POST /v1/messages/count_tokens.
Two deliberate differences from CreateResponse: input defaults (the
count endpoint accepts a body without one, whereas creating a response
requires it), and unknown fields are ignored, so stateful parameters
Dynamo does not serve (conversation, previous_response_id) are accepted
and disregarded rather than rejected. This endpoint reports a pre-flight
estimate; it never generates, so there is nothing for them to affect.
Deserialization is forgiving in two further places — an explicit
"input": null and unrecognized tool shapes — for the same reason
AnthropicTool keeps every field but name optional: a pre-flight
estimate that rejects a body it could have scored is strictly worse than
one that scores it approximately. See [deserialize_lenient_tools].
Fields§
§model: Option<String>§input: InputParam#[serde(default)] alone covers an absent input, but not an explicit
"input": null — serde still hands that null to InputParam, whose
deserializer rejects it. Here both mean “nothing to count”.
instructions: Option<String>§tools: Option<Vec<Tool>>Implementations§
Source§impl CountInputTokensRequest
impl CountInputTokensRequest
Sourcepub fn estimate_tokens(&self) -> u32
pub fn estimate_tokens(&self) -> u32
Estimate input token count using a len/3 heuristic.
Same contract as AnthropicCountTokensRequest::estimate_tokens: sum the
character lengths of everything that reaches the prompt, divide by three,
and never report zero for input that carried content.
This is an estimate, not a tokenization. A frontend serving a backend that tokenizes for itself has no tokenizer loaded, so this endpoint has to be able to answer without one.
Trait Implementations§
Source§impl Clone for CountInputTokensRequest
impl Clone for CountInputTokensRequest
Source§fn clone(&self) -> CountInputTokensRequest
fn clone(&self) -> CountInputTokensRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more