Tokenization
Use the selected model’s tokenizer to estimate a request before sending it. Messages, conversation history, and tool definitions all contribute to the estimate. The API response reports actual usage.
Send your first request to gpt-6-luna. For the prompt “What is 2 + 2? Answer with a digit,” one Chat Completions response included the following:
{ "model": "gpt-6-luna", "usage": { "prompt_tokens": 20, "completion_tokens": 4, "total_tokens": 24, "total_cost": 0.0008 }}prompt_tokens counts input tokens and completion_tokens counts output tokens. In this example, total_tokens is their sum, and total_cost is the cost in rubles. Usage may vary on subsequent calls.
The format of usage depends on the method. For a streaming response, keep the last usage data received before [DONE]. For embeddings, read the fields documented for that endpoint. In assistant chat, usage may also include knowledge base search.