Anthropic · Capability

Anthropic Token Counting API — Tokens

Anthropic Token Counting API — Tokens. 1 operation. Lead operation: Count Message Tokens. Self-contained Naftiko capability for counting input tokens on a prospective Messages request without creating it.

Anthropic Token Counting API — Tokens is a Naftiko capability published by Anthropic, one of 22 capabilities the APIs.io network indexes for this provider. It bundles 1 operation across the POST method rooted at /v1/messages/count_tokens.

The capability includes 1 read-only operation. Lead operation: Anthropic Count Message Tokens. Can be deployed as a REST endpoint, MCP tool, or Agent Skill via Naftiko.

Tagged areas include Anthropic, Tokens, and Counting.

Run with Naftiko AnthropicTokensCounting

What You Can Do

POST
Countmessagetokens — Anthropic Count Message Tokens
/v1/messages/count_tokens

MCP Tools

anthropic-count-message-tokens

Anthropic Count Message Tokens

read-only idempotent

Capability Spec

token-counting-tokens.yaml Raw ↑
naftiko: 1.0.0-alpha2
info:
  label: Anthropic Token Counting API — Tokens
  description: 'Anthropic Token Counting API — Tokens. 1 operation. Lead operation:
    Count Message Tokens. Self-contained Naftiko capability for counting input tokens
    on a prospective Messages request without creating it.'
  tags:
  - Anthropic
  - Tokens
  - Counting
  created: '2026-05-22'
  modified: '2026-05-22'
binds:
- namespace: env
  keys:
    ANTHROPIC_API_KEY: ANTHROPIC_API_KEY
capability:
  consumes:
  - type: http
    namespace: token-counting-tokens
    baseUri: https://api.anthropic.com
    description: Anthropic Token Counting API — count input tokens for any Messages
      request shape (including tools, images, and documents) without creating the
      message. Free to use; subject to RPM rate limits.
    headers:
      anthropic-version: '2023-06-01'
    resources:
    - name: v1-messages-count-tokens
      path: /v1/messages/count_tokens
      operations:
      - name: countmessagetokens
        method: POST
        description: Anthropic Count Message Tokens
        outputRawFormat: json
        outputParameters:
        - name: result
          type: object
          value: $.
        inputParameters:
        - name: body
          in: body
          type: object
          description: Messages request body to count.
          required: true
    authentication:
      type: apikey
      key: x-api-key
      value: '{{env.ANTHROPIC_API_KEY}}'
      placement: header
  exposes:
  - type: rest
    namespace: token-counting-tokens-rest
    port: 8080
    description: REST adapter for Token Counting API.
    resources:
    - path: /v1/messages/count_tokens
      name: v1-messages-count-tokens
      description: REST surface for token counting.
      operations:
      - method: POST
        name: countmessagetokens
        description: Anthropic Count Message Tokens
        call: token-counting-tokens.countmessagetokens
        with:
          body: rest.body
  - type: mcp
    namespace: token-counting-tokens-mcp
    port: 9090
    transport: http
    description: MCP adapter for Token Counting API.
    tools:
    - name: anthropic-count-message-tokens
      description: Anthropic Count Message Tokens
      hints:
        readOnly: true
        destructive: false
        idempotent: true
      call: token-counting-tokens.countmessagetokens
      with:
        body: tools.body