# Token counter

- Human page: https://happytails.ai/en/developer-tools/token-counter/
- Markdown: https://happytails.ai/en/developer-tools/token-counter.md
- Structured JSON: https://happytails.ai/agents/en/developer-tools/token-counter/index.json
- Visibility: public

## Tool capabilities

| Property | Value |
| --- | --- |
| Tool ID | `token-counter` |
| Category | developer-tools |
| Implementation | Registered implementation. Registration alone is not a production-quality guarantee. |
| Browser execution | Use the visible action or interactive controls. |
| Browser processing | Browser; see tool notes for network behavior. |
| HTTP API | /api/v1/tools/token-counter/run |
| Browser-agent interface | run_current_tool |

### Inputs and settings

Text input: Your text.

Example or placeholder shown in the interface (not a validated fixture):

```text
Type or paste your input…
```

Up to 1,000,000 characters. Review the settings before running.

| Setting | Meaning | Control type | Default | Constraints |
| --- | --- | --- | --- | --- |
| `model` | Tokenizer model | select | "gpt-4o" | Allowed: gpt-4o, gpt-4, gpt-3.5-turbo |

### HTTP contract

API calls process supplied data on the server. The website origin is `https://happytails.ai`. Server API hosting is not connected on the public website yet. Use your local server origin to test these requests.

```http
POST https://happytails.ai/api/v1/tools/token-counter/run
Content-Type: application/json
```

[Detailed operation reference](https://happytails.ai/en/api/tools/token-counter.md) · [Shared API guide](https://happytails.ai/en/api.md)

#### Limits

| Limit | Value |
| --- | --- |
| request_bytes | 8388608 |
| input_characters | 1000000 |
| files_bytes | 5242880 |
| max_files | 0 |
| timeout_seconds | 12 |

#### Complete input schema

```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "input": {
      "type": "string",
      "maxLength": 1000000,
      "default": "",
      "description": "Plain text input. File tools use files instead unless otherwise documented."
    },
    "options": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "model": {
          "type": "string",
          "description": "Tokenizer model",
          "default": "gpt-4o",
          "enum": [
            "gpt-4o",
            "gpt-4",
            "gpt-3.5-turbo"
          ]
        }
      }
    }
  }
}
```

#### Complete output schema

```json
{
  "type": "object",
  "required": [
    "tool",
    "result"
  ],
  "properties": {
    "tool": {
      "type": "string"
    },
    "result": {
      "type": "object",
      "required": [
        "text",
        "files"
      ],
      "properties": {
        "text": {
          "type": [
            "string",
            "null"
          ]
        },
        "data": {
          "description": "Parsed JSON when the textual result is JSON."
        },
        "name": {
          "type": "string"
        },
        "mime": {
          "type": "string"
        },
        "files": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "name",
              "mime",
              "bytes",
              "base64"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "mime": {
                "type": "string"
              },
              "bytes": {
                "type": "integer"
              },
              "base64": {
                "type": "string",
                "contentEncoding": "base64"
              }
            }
          }
        }
      }
    }
  }
}
```

#### Error and retry handling

Failures return a non-200 status and `error.code` plus `error.message`. Correct invalid input before retrying; retry server-busy responses with bounded backoff. Returned files contain Base64 data, not persistent download URLs. Decode and inspect the output before treating conversion as successful. See the shared API guide for the complete status and timeout rules.

### Browser-agent workflow

1. Open the human page in a browser that supports WebMCP.
2. Discover the interface exposed by that page; use its actual schema.
3. Select files on the page first when the tool requires files.
4. Call `run_current_tool` with valid input and settings.
5. Inspect the returned result or error and the displayed output. Retrieve files from the displayed download links.

Calls do not automatically copy or download results. Browser permissions still apply. Interface availability alone is not proof of successful execution.

### Planning specification

Explicit model/tokenizer version; local counts; no universal token-to-word conversion.

This describes intended requirements. Use the implementation notes, interface schema and observed output to determine current support.

### Complete machine-readable capability record

```json
{
  "id": "token-counter",
  "category": "developer-tools",
  "built": true,
  "requirements": "Explicit model/tokenizer version; local counts; no universal token-to-word conversion.",
  "implementation": {
    "fields": [
      {
        "key": "model",
        "label": "Tokenizer model",
        "value": "gpt-4o",
        "type": "select",
        "values": [
          "gpt-4o",
          "gpt-4",
          "gpt-3.5-turbo"
        ]
      }
    ],
    "experience": {
      "automatic": false,
      "single": false,
      "label": "Your text",
      "placeholder": "Type or paste your input…",
      "help": "Up to 1,000,000 characters. Review the settings before running.",
      "action": null
    },
    "mode": "explicit",
    "interactive": false
  },
  "execution": "POST /api/v1/tools/token-counter/run",
  "api": {
    "id": "token-counter",
    "name": "Token counter",
    "category": "developer-tools",
    "description": "Explicit model/tokenizer version.",
    "notes": "",
    "human_path": "/en/developer-tools/token-counter/",
    "method": "POST",
    "endpoint": "/api/v1/tools/token-counter/run",
    "schema_url": "/api/v1/tools/token-counter",
    "input_schema": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "input": {
          "type": "string",
          "maxLength": 1000000,
          "default": "",
          "description": "Plain text input. File tools use files instead unless otherwise documented."
        },
        "options": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "model": {
              "type": "string",
              "description": "Tokenizer model",
              "default": "gpt-4o",
              "enum": [
                "gpt-4o",
                "gpt-4",
                "gpt-3.5-turbo"
              ]
            }
          }
        }
      }
    },
    "output_schema": {
      "type": "object",
      "required": [
        "tool",
        "result"
      ],
      "properties": {
        "tool": {
          "type": "string"
        },
        "result": {
          "type": "object",
          "required": [
            "text",
            "files"
          ],
          "properties": {
            "text": {
              "type": [
                "string",
                "null"
              ]
            },
            "data": {
              "description": "Parsed JSON when the textual result is JSON."
            },
            "name": {
              "type": "string"
            },
            "mime": {
              "type": "string"
            },
            "files": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "name",
                  "mime",
                  "bytes",
                  "base64"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "base64": {
                    "type": "string",
                    "contentEncoding": "base64"
                  }
                }
              }
            }
          }
        }
      }
    },
    "processing": "Server; same transformation code as browser tools",
    "limits": {
      "request_bytes": 8388608,
      "input_characters": 1000000,
      "files_bytes": 5242880,
      "max_files": 0,
      "timeout_seconds": 12
    }
  },
  "agent_processing": "Server; same transformation code as browser tools",
  "browser_agent": {
    "supported": true,
    "name": "run_current_tool",
    "discovery": "WebMCP on the human page in a supporting browser",
    "verification": "See audit/API-AUDIT.md; availability is not verification"
  }
}
```

## Page guide

Explicit model/tokenizer version.

## How to use Token counter

1. Enter your text in the input field.
2. Review the settings, then choose Run Token counter.
3. Review the result, then use Copy result or a download link when available.

## Working with token counter

Formatting makes existing data or code easier to read. Validation checks whether it follows a syntax or schema. Conversion maps it into another representation. Choosing the right operation helps avoid treating a neatly formatted result as proof that the underlying data is correct.

## Common questions

### Does valid JSON mean the data is correct?

Syntax validation only establishes that the text can be parsed as JSON. A schema can check required fields and types, but neither proves that an email address, price or external record is factually correct.

### Is decoding the same as decrypting or verifying?

No. Base64 and URL encoding are representations, not encryption. Reading a token payload does not verify its signature. Use the specific validation or verification process required by the system receiving the result.
