{"openapi":"3.0.3","info":{"title":"AI Token Counter API","version":"2.0.0","description":"Token counting and cost estimation for GPT-4o, Claude, Gemini, Mistral, Llama. No API key required for /count, /count/batch, /pricing, /estimate-cost.","contact":{"url":"https://api.lazy-mac.com/ai-token-counter"}},"servers":[{"url":"https://api.lazy-mac.com/ai-token-counter"}],"paths":{"/health":{"get":{"summary":"Health check","operationId":"healthCheck","responses":{"200":{"description":"Service health"}}}},"/models":{"get":{"summary":"List all supported models grouped by family","operationId":"listModels","responses":{"200":{"description":"Model list"}}}},"/pricing":{"get":{"summary":"List pricing for all supported models","operationId":"listPricing","responses":{"200":{"description":"Full pricing table"}}}},"/pricing/{model}":{"get":{"summary":"Get pricing for a specific model","operationId":"getModelPricing","parameters":[{"name":"model","in":"path","required":true,"schema":{"type":"string"},"example":"gpt-4o","description":"Model ID, e.g. gpt-4o, claude-opus-4, gemini-2.0-flash"}],"responses":{"200":{"description":"Pricing details with examples"},"404":{"description":"Unknown model"}}}},"/count":{"post":{"summary":"Count tokens for text or messages array","operationId":"countTokens","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"model":{"type":"string","example":"gpt-4o","description":"Model ID (determines tokenizer). Defaults to gpt-4o."},"text":{"type":"string","description":"Plain text to count tokens for. Mutually exclusive with messages."},"messages":{"type":"array","description":"Chat messages array (OpenAI/Anthropic format). Mutually exclusive with text.","items":{"type":"object","properties":{"role":{"type":"string"},"content":{}}}}}},"examples":{"text":{"summary":"Count text tokens","value":{"model":"gpt-4o","text":"How many tokens is this sentence?"}},"messages":{"summary":"Count chat message tokens","value":{"model":"claude-sonnet-4","messages":[{"role":"user","content":"What is 2+2?"}]}}}}}},"responses":{"200":{"description":"Token count result","content":{"application/json":{"schema":{"type":"object","properties":{"model":{"type":"string"},"tokens":{"type":"integer"},"method":{"type":"string","enum":["text","messages"]},"fits_context":{"type":"boolean","nullable":true},"context_limit":{"type":"integer","nullable":true},"note":{"type":"string"}}}}}},"400":{"description":"Validation error"}}}},"/count/batch":{"post":{"summary":"Count tokens for multiple texts/message arrays in one call (max 100 items)","operationId":"countTokensBatch","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["items"],"properties":{"items":{"type":"array","maxItems":100,"items":{"type":"object","properties":{"model":{"type":"string"},"text":{"type":"string"},"messages":{"type":"array","items":{"type":"object"}}}}}}},"example":{"items":[{"model":"gpt-4o","text":"Hello world"},{"model":"claude-sonnet-4","messages":[{"role":"user","content":"Hi"}]}]}}}},"responses":{"200":{"description":"Batch results with per-item token counts and total"},"400":{"description":"Validation error"}}}},"/estimate-cost":{"post":{"summary":"Estimate cost for a request given model + token counts or text","operationId":"estimateCost","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["model"],"properties":{"model":{"type":"string","example":"gpt-4o"},"input_tokens":{"type":"integer","description":"Input token count. If omitted, computed from text or messages."},"output_tokens":{"type":"integer","description":"Output token count. If omitted, estimated as output_ratio * input_tokens."},"output_ratio":{"type":"number","default":0.3,"description":"Ratio of output to input tokens when output_tokens is omitted."},"text":{"type":"string","description":"Text to tokenize for input_tokens (if input_tokens not given)."},"messages":{"type":"array","items":{"type":"object"},"description":"Messages to tokenize (if input_tokens not given)."},"requests_per_day":{"type":"number","description":"If given, adds daily/monthly/yearly projection."}}},"examples":{"simple":{"summary":"Estimate by token count","value":{"model":"gpt-4o","input_tokens":1000,"output_tokens":500}},"text":{"summary":"Estimate from text","value":{"model":"claude-sonnet-4","text":"Summarize this long document...","output_ratio":0.5,"requests_per_day":10000}}}}}},"responses":{"200":{"description":"Cost breakdown with optional monthly projection"},"400":{"description":"Validation error or unknown model"}}}},"/mcp":{"get":{"summary":"MCP endpoint info","operationId":"mcpInfo","responses":{"200":{"description":"MCP server metadata and example body"}}},"post":{"summary":"MCP JSON-RPC 2.0 endpoint","operationId":"mcpRpc","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["jsonrpc","method"],"properties":{"jsonrpc":{"type":"string","enum":["2.0"]},"method":{"type":"string"},"id":{},"params":{"type":"object"}}}}}},"responses":{"200":{"description":"JSON-RPC response"}}}}}}