openapi: 3.1.0 info: title: Anthropic Claude Messages Message Batches Token Counting API version: '2023-06-01' description: 'REST API for sending messages to Claude models with support for streaming, tool use, vision, system prompts, prompt caching, and extended thinking. Authentication uses an x-api-key header along with an anthropic-version header. ' contact: name: Anthropic Support url: https://support.anthropic.com license: name: Anthropic Commercial Terms of Service url: https://www.anthropic.com/legal/commercial-terms servers: - url: https://api.anthropic.com description: Anthropic API production security: - ApiKeyAuth: [] tags: - name: Token Counting description: Count tokens for a prospective Messages request. paths: /v1/messages/count_tokens: post: tags: - Token Counting summary: Count tokens for a Messages request description: Count the number of input tokens that a Messages request would consume, without actually creating a Message. operationId: countMessageTokens parameters: - $ref: '#/components/parameters/AnthropicVersion' - $ref: '#/components/parameters/AnthropicBeta' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/CountTokensRequest' responses: '200': description: Token count response. content: application/json: schema: $ref: '#/components/schemas/CountTokensResponse' '400': $ref: '#/components/responses/ErrorResponse' components: schemas: CountTokensResponse: type: object properties: input_tokens: type: integer cache_creation_input_tokens: type: integer cache_read_input_tokens: type: integer InputMessage: type: object required: - role - content properties: role: type: string enum: - user - assistant content: oneOf: - type: string - type: array items: type: object Tool: type: object required: - name - input_schema properties: name: type: string description: type: string input_schema: type: object CountTokensRequest: type: object required: - model - messages properties: model: type: string messages: type: array items: $ref: '#/components/schemas/InputMessage' system: oneOf: - type: string - type: array items: type: object tools: type: array items: $ref: '#/components/schemas/Tool' Error: type: object properties: type: type: string error: type: object properties: type: type: string message: type: string parameters: AnthropicBeta: name: anthropic-beta in: header required: false description: Optional comma-separated list of beta feature flags. schema: type: string AnthropicVersion: name: anthropic-version in: header required: true description: API version, e.g. `2023-06-01`. schema: type: string default: '2023-06-01' responses: ErrorResponse: description: An error response. content: application/json: schema: $ref: '#/components/schemas/Error' securitySchemes: ApiKeyAuth: type: apiKey in: header name: x-api-key description: Anthropic API key. Send as the `x-api-key` header on every request.