Claude · Arazzo Workflow

Claude Count Tokens Then Create Message

Version 1.0.0

Pre-flight a prompt through token counting before sending it to the Messages API.

1 workflow 1 source API 1 provider
View Spec View on GitHub Artificial IntelligenceChatbotsConversational AIGenerative AILarge Language ModelsMachine-LearningNatural Language ProcessingArazzoWorkflows

Provider

claude

Workflows

count-tokens-then-create-message
Count input tokens for a prompt, then generate a message with the same prompt.
Counts the input tokens for a model and prompt, then sends the prompt to the Messages API, returning both the pre-flight token count and the generated message usage.
2 steps inputs: anthropicVersion, apiKey, maxTokens, model, prompt outputs: content, estimatedInputTokens, messageId, usage
1
countTokens
Count the number of input tokens the prompt will consume for the chosen model, without creating a message.
2
createMessage
Send the same prompt to the Messages API now that its token footprint is known, capturing the generated content and usage.

Source API Descriptions

Arazzo Workflow Specification

Raw ↑
arazzo: 1.0.1
info:
  title: Claude Count Tokens Then Create Message
  summary: Pre-flight a prompt through token counting before sending it to the Messages API.
  description: >-
    A budget-aware completion flow. The workflow first counts the number of
    input tokens a prompt would consume using the count_tokens endpoint, then
    sends the same prompt to the Messages API to generate a response. Counting
    first lets a caller verify the request fits within a model's context window
    and estimate cost before incurring generation charges. Every step spells
    out its request inline — including the required x-api-key and
    anthropic-version headers — so the flow can be read and executed without
    opening the underlying OpenAPI description.
  version: 1.0.0
sourceDescriptions:
- name: messagesApi
  url: ../openapi/claude-messages-api-openapi.yml
  type: openapi
workflows:
- workflowId: count-tokens-then-create-message
  summary: Count input tokens for a prompt, then generate a message with the same prompt.
  description: >-
    Counts the input tokens for a model and prompt, then sends the prompt to the
    Messages API, returning both the pre-flight token count and the generated
    message usage.
  inputs:
    type: object
    required:
    - apiKey
    - model
    - prompt
    properties:
      apiKey:
        type: string
        description: Anthropic API key sent in the x-api-key header.
      anthropicVersion:
        type: string
        description: Value for the required anthropic-version header.
        default: '2023-06-01'
      model:
        type: string
        description: The model to count tokens for and to generate the message with.
      prompt:
        type: string
        description: The user prompt to count and send.
      maxTokens:
        type: integer
        description: Maximum number of tokens to generate in the response.
        default: 1024
  steps:
  - stepId: countTokens
    description: >-
      Count the number of input tokens the prompt will consume for the chosen
      model, without creating a message.
    operationId: countMessageTokens
    parameters:
    - name: x-api-key
      in: header
      value: $inputs.apiKey
    - name: anthropic-version
      in: header
      value: $inputs.anthropicVersion
    requestBody:
      contentType: application/json
      payload:
        model: $inputs.model
        messages:
        - role: user
          content: $inputs.prompt
    successCriteria:
    - condition: $statusCode == 200
    outputs:
      inputTokens: $response.body#/input_tokens
  - stepId: createMessage
    description: >-
      Send the same prompt to the Messages API now that its token footprint is
      known, capturing the generated content and usage.
    operationId: createMessage
    parameters:
    - name: x-api-key
      in: header
      value: $inputs.apiKey
    - name: anthropic-version
      in: header
      value: $inputs.anthropicVersion
    requestBody:
      contentType: application/json
      payload:
        model: $inputs.model
        max_tokens: $inputs.maxTokens
        messages:
        - role: user
          content: $inputs.prompt
    successCriteria:
    - condition: $statusCode == 200
    outputs:
      messageId: $response.body#/id
      content: $response.body#/content
      stopReason: $response.body#/stop_reason
      usage: $response.body#/usage
  outputs:
    estimatedInputTokens: $steps.countTokens.outputs.inputTokens
    messageId: $steps.createMessage.outputs.messageId
    content: $steps.createMessage.outputs.content
    usage: $steps.createMessage.outputs.usage

Work with this as data

Every workflow here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for arazzo workflows

4 MCP tools reach this
  • find_arazzoBrowse and filter every workflow in the catalog.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This workflow
curl "https://apis.io/api/v1/arazzo/claude-count-tokens-then-create-message-workflow"
All arazzo workflows
curl "https://apis.io/api/v1/arazzo?limit=25"

Discovery needs no key. Ratings and market analysis are Pro.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.