> ## Documentation Index
> Fetch the complete documentation index at: https://docs.promptguard.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Proxy Count Tokens

> Proxy Anthropic's token-counting endpoint.

A compatibility gap rather than a security surface: an Anthropic SDK pointed
at PromptGuard breaks on `client.messages.count_tokens()` because we did not
serve the route. It counts tokens and returns a number -- nothing reaches a
model and nothing is generated, so there is no completion to scan.

The request still goes through the same handler as the rest, which means the
prompt IS scanned on the way in. That is deliberate: the body is a full
`messages` array, so it is a place a caller could otherwise probe or stage
content with no policy applied.

Note this is NOT what enforces `max_tokens_per_request`. That runs inline on
every request and must not make a network call to do it -- see
shared/security/token_limiter.py.



## OpenAPI

````yaml /api-reference/openapi-developer.json post /api/v1/messages/count_tokens
openapi: 3.1.0
info:
  title: PromptGuard Developer API
  description: >-
    Public API for developers to integrate PromptGuard security into their
    applications
  version: 1.0.0
servers:
  - url: https://api.promptguard.co
    description: Production
security:
  - ApiKeyAuth: []
paths:
  /api/v1/messages/count_tokens:
    post:
      summary: Proxy Count Tokens
      description: >-
        Proxy Anthropic's token-counting endpoint.


        A compatibility gap rather than a security surface: an Anthropic SDK
        pointed

        at PromptGuard breaks on `client.messages.count_tokens()` because we did
        not

        serve the route. It counts tokens and returns a number -- nothing
        reaches a

        model and nothing is generated, so there is no completion to scan.


        The request still goes through the same handler as the rest, which means
        the

        prompt IS scanned on the way in. That is deliberate: the body is a full

        `messages` array, so it is a place a caller could otherwise probe or
        stage

        content with no policy applied.


        Note this is NOT what enforces `max_tokens_per_request`. That runs
        inline on

        every request and must not make a network call to do it -- see

        shared/security/token_limiter.py.
      operationId: proxy_count_tokens_api_v1_messages_count_tokens_post
      parameters:
        - name: x-api-key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Api-Key
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: >-
        PromptGuard API key for developer endpoints. Keys start with pg_live_
        and are created in the dashboard.

````