capabilities.work

Count Tokens Then Create Message

A 2-step recipe with Anthropic. We can help you get access.

Recipe · 2 steps

Count Tokens Then Create Message

Count input tokens for a prompt and conditionally create the message.

  1. Count the input tokens for the prospective message request without creating the message or charging output tokens.
  2. Send the prompt as a real message now that the input token total is known to be within budget, and capture the generated response.
What you'll need to have ready
  • apiKey: A valid Anthropic API key sent in the x-api-key header.
  • model: The Claude model id to count against and generate with.
  • prompt: The user prompt text to evaluate and send.
  • tokenBudget: The maximum acceptable input token count before sending the message.
  • maxTokens: Maximum number of output tokens to generate.
For your developer

Arazzo workflow anthropic:count-tokens-then-message, 2 operations: countMessageTokens → messages_post. Specs on APIs.io.