Access the Token Calculator API to integrate token counting and cost estimation into your own applications.
The TokenCalculator.com API provides programmatic access to our token counting and cost estimation features. With our API, you can:
All API requests require authentication using an API key. You can obtain your API key by contacting us.
Include your API key in the request header:
Authorization: Bearer YOUR_API_KEY
All API requests should be made to:
https://tokencalculator.com/api/v1
Count the number of tokens in a given text.
{ "text": "Your text to be tokenized", "tokenizer": "cl100k_base" // Optional, defaults to cl100k_base }
{ "success": true, "token_count": 5, "characters": 25, "words": 5, "tokenizer": "cl100k_base" }
Calculate the cost for a specific model based on input and output tokens.
{ "model_id": "gpt-4o", "input_tokens": 1000, "output_tokens": 500 }
{ "success": true, "model_id": "gpt-4o", "input_cost": 0.01, "output_cost": 0.03, "total_cost": 0.04, "currency": "USD" }
Retrieve a list of all available models or models from a specific provider.
provider: (optional) Filter by provider name (e.g., openai, anthropic)
{ "success": true, "models": [ { "id": "gpt-4o", "name": "GPT-4o", "provider": "OpenAI", "context": "128K", "input_price_per_1m": 5.0, "output_price_per_1m": 15.0, "tokenizer_id": "cl100k_base" }, // ... more models ] }
Retrieve detailed information about a specific model.
model_id: The ID of the model to retrieve
{ "success": true, "model": { "id": "gpt-4o", "name": "GPT-4o", "provider": "OpenAI", "description": "GPT-4o is OpenAI's latest multimodal model...", "context": "128K", "input_price_per_1m": 5.0, "output_price_per_1m": 15.0, "tokenizer_id": "cl100k_base", "released": "2024-05", "capabilities": ["text", "images", "audio"], "url": "https://openai.com/gpt-4o" } }
The API is rate-limited to protect our services from excessive usage. The current limits are:
When an error occurs, the API will return an appropriate HTTP status code and a JSON response with details about the error.
{ "success": false, "error": { "code": "invalid_request", "message": "The request was invalid. Please check your parameters and try again." } }
If you need help with the API or have questions, please contact our support team.