Most services return the number of tokens used, and some also return the price. When a service returns nothing, AI Engine estimates the tokens and calculates the price from its own model list.
Services
| Hosting Service | Streaming | Tokens Usage | Price Usage | Notes |
|---|---|---|---|---|
| OpenAI (+ Azure) | No | ❤️ Returned by OpenAI | ❤️ Calculated by AI Engine | |
| OpenAI (+ Azure) | Yes | ❤️ Returned by OpenAI | ❤️ Calculated by AI Engine | |
| OpenRouter | No | ❤️ Returned by OpenRouter | ❤️ Returned by OpenRouter | |
| OpenRouter | Yes | ❤️ Returned by OpenRouter | ❤️ Returned by OpenRouter | Included in the stream, no extra request. |
| Anthropic (Claude) | Any | ❤️ Returned by Anthropic | ❤️ Calculated by AI Engine | |
| Any | ❤️ Returned by Google | ❤️ Calculated by AI Engine | https://ai.google.dev/pricing |
⚠️ When the tokens are not returned: Guessed by AI Engine
This is done through the estimate_tokens function in the core. In fact, the implementation of each model could do it differently, but there is currently no way to know how each service actually calculate those tokens (since they depend on how the messages are actually formatted, how the images are counted, etc). This is highly inaccurate. If you depend on this, use something else. You can also plug in your own calculation with the mwai_estimate_tokens filter (see PHP Filters).