count tokens

This block is part of the anthropic group and was last modified in core v15.0.0.

count tokens v15.0.0

Count the input tokens a prompt (with system + attachments) would use, and estimate the cost; before you send it. Free; no spend.

In pins 6 + flow
  • flow
    flow
  • connection required
    anthropicconnection
  • prompt
    value

    The user message to measure.

  • system
    value

    Optional system prompt to include in the count.

  • attachments
    file

    Optional images/PDFs; their tokens are counted by the API too.

  • model
    value

    Model to price against. Defaults to the connection's default model. • Suggestions: claude-opus-4-8 claude-sonnet-4-6 claude-haiku-4-5

  • max tokens
    number

    Max output tokens, for the worst-case output cost estimate. Default 16000.

Out pins 11 + flow
  • flow
    flow
  • connection
    anthropicconnection
  • success
    condition
  • model
    value
  • input tokens
    number

    Tokens the prompt + system + attachments would use.

  • max tokens
    number

    The max output tokens used for the output-cost estimate.

  • input cost (USD)
    number

    Cost of the counted input tokens.

  • max output cost (USD)
    number

    Worst-case output cost if generation used the full max_tokens.

  • estimated total (USD)
    number

    input cost + max output cost (the upper bound for a single call).

  • errors
    array<value>

    Error codes when the call fails (success=false): config_error, rate_limited, transport_error.

  • warnings
    array<value>

    Non-fatal notices: cost_unknown (model not in the price table; costs reported as 0).

  • error detail
    value
token count
estimate cost
tokens
price check
how much

A typical wiring for count tokens: a function trigger starts the flow; the flow out pin feeds debug.

Studio canvas example for the count tokens block: typical wiring for count tokens.

Version history

Introduced in v15.0.0.


Back to anthropic Return to the main group to view all sub-groups Back to anthropic Return to the group to view all blocks within this group