MVFM

anthropic/count_tokens

Count tokens for a message request without sending it

const app = mvfm(prelude, console_, anthropic_);
const prog = app({}, ($) => {
  const count = $.anthropic.messages.countTokens({
    model: "claude-sonnet-4-20250514",
    messages: [{ role: "user", content: "How many tokens is this?" }],
  });
  return $.console.log(count);
});
await fold(defaults(app, { anthropic: crystalBallAnthropicInterpreter }), prog);
Ctrl+Enter