---
title: "Count tokens"
method: POST
path: "/v1/responses/input_tokens"
tags: ["Count Tokens"]
---

# Count tokens

`POST /v1/responses/input_tokens`

Counts the number of tokens in the provided messages.

## Request body

- CountTokensRequest
  - `model` string, required — Model in provider/model format
  - `messages` object[], required
    - `id` string
    - `type` 'message' | 'file_search_call' | 'computer_call' | 'computer_call_output' | 'web_search_call' | 'web_fetch_call' | 'function_call' | 'function_call_output' | 'code_interpreter_call' | 'local_shell_call' | 'local_shell_call_output' | 'mcp_call' | 'custom_tool_call' | 'custom_tool_call_output' | 'image_generation_call' | 'mcp_list_tools' | 'mcp_approval_request' | 'mcp_approval_responses' | 'reasoning' | 'item_reference' | 'refusal'
    - `status` 'in_progress' | 'completed' | 'incomplete' | 'interpreting' | 'failed'
    - `role` 'assistant' | 'user' | 'system' | 'developer'
    - `content` union
      - string
      - object[]
        - `type` 'input_text' | 'input_image' | 'input_file' | 'input_audio' | 'output_text' | 'refusal' | 'reasoning_text', required
        - `file_id` string
        - `text` string
        - `signature` string
        - `image_url` string
        - `detail` string
        - `file_data` string
        - `file_url` string
        - `filename` string
        - `file_type` string
        - `input_audio` object
          - `format` 'mp3' | 'wav', required
          - `data` string, required
        - `annotations` object[]
          - `type` 'file_citation' | 'url_citation' | 'container_file_citation' | 'file_path'
          - `index` integer
          - `file_id` string
          - `text` string
          - `start_index` integer
          - `end_index` integer
          - `filename` string
          - `title` string
          - `url` string
          - `container_id` string
        - `logprobs` object[]
          - `bytes` integer[]
          - `logprob` number
          - `token` string
          - `top_logprobs` object[]
            - `bytes` integer[]
            - `logprob` number
            - `token` string
        - `refusal` string
        - `cache_control` CacheControl — Cache control settings for content blocks
          - `type` 'ephemeral'
          - `ttl` string — Time to live (e.g., "1m", "1h")
    - `call_id` string
    - `name` string
    - `arguments` string
    - `output` union — Tool call output. A plain string for function/custom/local-shell tool outputs, an array of content blocks for structured function tool outputs, or a computer-tool screenshot object for computer_call_output.
      - string
      - object[]
        - `type` 'input_text' | 'input_image' | 'input_file' | 'input_audio' | 'output_text' | 'refusal' | 'reasoning_text', required
        - `file_id` string
        - `text` string
        - `signature` string
        - `image_url` string
        - `detail` string
        - `file_data` string
        - `file_url` string
        - `filename` string
        - `file_type` string
        - `input_audio` object
          - `format` 'mp3' | 'wav', required
          - `data` string, required
        - `annotations` object[]
          - `type` 'file_citation' | 'url_citation' | 'container_file_citation' | 'file_path'
          - `index` integer
          - `file_id` string
          - `text` string
          - `start_index` integer
          - `end_index` integer
          - `filename` string
          - `title` string
          - `url` string
          - `container_id` string
        - `logprobs` object[]
          - `bytes` integer[]
          - `logprob` number
          - `token` string
          - `top_logprobs` object[]
            - `bytes` integer[]
            - `logprob` number
            - `token` string
        - `refusal` string
        - `cache_control` CacheControl — Cache control settings for content blocks
          - `type` 'ephemeral'
          - `ttl` string — Time to live (e.g., "1m", "1h")
      - object — Computer tool call output (computer_screenshot).
        - `type` 'computer_screenshot'
        - `file_id` string
        - `image_url` string
    - `action` object
    - `error` string
    - `queries` string[]
    - `results` object[]
    - `summary` object[]
      - `type` 'summary_text', required
      - `text` string, required
    - `encrypted_content` string
  - `fallbacks` string[]
  - `tools` object[]
    - `type` 'function' | 'file_search' | 'computer_use_preview' | 'web_search' | 'web_fetch' | 'mcp' | 'code_interpreter' | 'image_generation' | 'local_shell' | 'custom' | 'web_search_preview' | 'memory' | 'tool_search', required
    - `name` string
    - `description` string
    - `cache_control` CacheControl — Cache control settings for content blocks
      - `type` 'ephemeral'
      - `ttl` string — Time to live (e.g., "1m", "1h")
    - `parameters` object
      - `type` string
      - `description` string
      - `required` string[]
      - `properties` object
      - `enum` string[]
      - `additionalProperties` boolean
    - `strict` boolean
    - `vector_store_ids` string[]
    - `filters` object
    - `max_num_results` integer
    - `ranking_options` object
    - `display_height` integer
    - `display_width` integer
    - `environment` string
    - `enable_zoom` boolean
    - `search_context_size` string
    - `user_location` object
    - `server_label` string
    - `server_url` string
    - `allowed_tools` object
    - `authorization` string
    - `connector_id` string
    - `headers` object
    - `require_approval` object
    - `server_description` string
    - `container` object
    - `background` string
    - `input_fidelity` string
    - `input_image_mask` object
    - `moderation` string
    - `output_compression` integer
    - `output_format` string
    - `partial_images` integer
    - `quality` string
    - `size` string
    - `format` object
  - `instructions` string
  - `text` string

## Response `200`

Successful response

- CountTokensResponse
  - `object` string
  - `model` string
  - `input_tokens` integer
  - `input_tokens_details` object
    - `text_tokens` integer
    - `audio_tokens` integer
    - `image_tokens` integer
    - `cached_read_tokens` integer — Tokens served from the prompt cache (cache hit), billed at the reduced cache-read rate. Already included in the parent input_tokens total.
    - `cached_write_tokens` integer — Tokens written to the prompt cache on this request, billed at the cache-creation rate. Already included in the parent input_tokens total. Populated for providers that separately report cache write tokens (Anthropic, Bedrock).
  - `tokens` integer[]
  - `token_strings` string[]
  - `output_tokens` integer
  - `total_tokens` integer
  - `extra_fields` BifrostResponseExtraFields — Additional fields included in responses
    - `request_type` string — Type of request that was made
    - `provider` 'openai' | 'azure' | 'anthropic' | 'bedrock' | 'cohere' | 'vertex' | 'vllm' | 'mistral' | 'ollama' | 'groq' | 'sgl' | 'parasail' | 'perplexity' | 'replicate' | 'cerebras' | 'deepseek' | 'gemini' | 'openrouter' | 'elevenlabs' | 'huggingface' | 'nebius' | 'xai' | 'runway' | 'fireworks' — AI model provider identifier
    - `model_requested` string — The model that was requested
    - `model_deployment` string — The actual model deployment used
    - `latency` integer — Request latency in milliseconds
    - `chunk_index` integer — Index of the chunk for streaming responses
    - `raw_request` object — Raw request if enabled
    - `raw_response` object — Raw response if enabled
    - `cache_debug` BifrostCacheDebug
      - `cache_hit` boolean
      - `cache_id` string
      - `hit_type` string
      - `requested_provider` string
      - `requested_model` string
      - `provider_used` string
      - `model_used` string
      - `input_tokens` integer
      - `threshold` number
      - `similarity` number

## Other responses

- `400` — Bad request
- `500` — Internal server error

---

[API](https://skmtc.net/getbifrost/apis/bifrost-api.md) · [All operations](https://skmtc.net/getbifrost/apis/bifrost-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/getbifrost/bifrost-api/revisions/f8cab88f64ea/schema)
