{"openapi":"3.1.0","info":{"title":"tokencalc API","version":"0.1.0","description":"Token counts and API costs for cloud and local language models. Counts are exact where a public tokenizer exists and labelled estimates otherwise. Prices are USD per 1 million tokens with an as-of date. No request text is stored.","contact":{"url":"https://tokencalc.io/mcp"}},"servers":[{"url":"https://tokencalc.io"}],"paths":{"/api/v1/models":{"get":{"operationId":"listModels","summary":"Models, context windows and prices","parameters":[{"name":"vendor","in":"query","schema":{"type":"string"}},{"name":"kind","in":"query","schema":{"type":"string","enum":["cloud","local"]}},{"name":"min_context","in":"query","schema":{"type":"integer"}}],"responses":{"200":{"description":"Model list","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/count":{"post":{"operationId":"countTokens","summary":"Count tokens","description":"Counts a text for up to 10 models. `exact: true` asks the vendor token endpoints (needs an API key or a verified browser request).","requestBody":{"required":true,"content":{"application/json":{"schema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"text":{"type":"string","description":"The text to count"},"models":{"description":"Model ids from list_models (max 10). Default: one model each from OpenAI, Anthropic, Google","minItems":1,"maxItems":10,"type":"array","items":{"type":"string","minLength":1,"maxLength":64}},"exact":{"description":"Ask the vendor token endpoints for exact counts of closed tokenizers (Claude, Gemini, Grok). Sends the text to that vendor.","type":"boolean"}},"required":["text"],"additionalProperties":false}}}},"responses":{"200":{"description":"Result","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/cost":{"post":{"operationId":"estimateCost","summary":"Estimate cost","description":"Cost per call and per month with caching, batch and long-context price rows.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"model":{"type":"string","minLength":1,"maxLength":64},"input_tokens":{"type":"number","minimum":0,"description":"All prompt tokens of one call, including any cached part"},"output_tokens":{"default":0,"type":"number","minimum":0},"cache_read_tokens":{"type":"number","minimum":0},"cache_write_tokens":{"type":"number","minimum":0},"cache_long":{"description":"Use the long cache lifetime price (Anthropic: 1 hour)","type":"boolean"},"batch":{"description":"Use the batch API price","type":"boolean"},"calls_per_month":{"type":"number","minimum":0},"on_date":{"description":"Price date; announced price changes apply from their effective date","type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"}},"required":["model","input_tokens","output_tokens"],"additionalProperties":false}}}},"responses":{"200":{"description":"Result","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/compare":{"post":{"operationId":"compareModels","summary":"Compare models","description":"Ranks models by cost for the same text or token count.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"text":{"description":"Text to count per model. Give this or input_tokens","type":"string"},"input_tokens":{"type":"number","minimum":0},"output_tokens":{"default":0,"description":"Expected answer length in tokens","type":"number","minimum":0},"models":{"minItems":1,"maxItems":10,"type":"array","items":{"type":"string","minLength":1,"maxLength":64}},"calls_per_month":{"type":"number","minimum":0}},"required":["output_tokens"],"additionalProperties":false}}}},"responses":{"200":{"description":"Result","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/fit":{"post":{"operationId":"fitContext","summary":"Context fit","description":"Checks a prompt size against context windows.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"input_tokens":{"type":"number","minimum":0},"reserve_output":{"default":0,"description":"Tokens to keep free for the answer and thinking","type":"number","minimum":0},"models":{"minItems":1,"maxItems":10,"type":"array","items":{"type":"string","minLength":1,"maxLength":64}}},"required":["input_tokens","reserve_output"],"additionalProperties":false}}}},"responses":{"200":{"description":"Result","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/caching-breakeven":{"post":{"operationId":"cachingBreakeven","summary":"Caching break-even","description":"Saving from prompt caching and the reuse count at which it pays back.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"model":{"type":"string","minLength":1,"maxLength":64},"prefix_tokens":{"type":"number","exclusiveMinimum":0,"description":"Size of the repeated prompt prefix"},"reuses":{"type":"integer","minimum":0,"maximum":9007199254740991,"description":"How many more calls reuse the prefix inside the cache lifetime"},"long":{"description":"Long cache lifetime (Anthropic: 1 hour)","type":"boolean"}},"required":["model","prefix_tokens","reuses"],"additionalProperties":false}}}},"responses":{"200":{"description":"Result","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/api/v1/optimize":{"post":{"operationId":"optimizePrompt","summary":"Shrink a prompt","description":"Deterministic rewrites with measured token savings. No language model is called.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"text":{"type":"string"},"model":{"description":"Model whose tokenizer measures the saving. Default gpt-6.1-sol","type":"string","minLength":1,"maxLength":64},"include_output":{"description":"Return the rewritten text of each candidate (default true)","type":"boolean"}},"required":["text"],"additionalProperties":false}}}},"responses":{"200":{"description":"Result","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}},"components":{"schemas":{"Error":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string"},"message":{"type":"string"}},"required":["code","message"]}},"required":["error"]}},"securitySchemes":{"apiKey":{"type":"apiKey","in":"header","name":"x-api-key","description":"Optional. Raises rate limits and enables exact vendor counts."}}}}