Get the total tokens used in the image description
Currently, I only get the result of the image description in the pipeline.
I also need to get the total tokens consumed in the request to the remote model.
Example:
return {
"response": res.choices[0].message.content,
"tokens": {
"prompt": res.usage.prompt_tokens,
"completion": res.usage.completion_tokens,
"total": res.usage.total_tokens,
}
}
The image description pipeline currently does not return token usage (prompt, completion, total tokens) in its response. While the remote model API may provide this information in a usage field (as in OpenAI-compatible APIs), the pipeline only returns the generated text and does not propagate token usage data through its models or responses. To include token usage in your output, you would need to modify the pipeline to extract the usage field from the remote API response and add it to your result object, updating the relevant data models and response logic to support this structure. For remote APIs that do not provide token usage, you may need to estimate or handle missing values as appropriate. For more details on the expected response structure and proxying non-OpenAI APIs, see this discussion and this issue.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
Hi @ezequiel88,
You can capture token usage from the API using a custom plugin approach. I've published a working implementation here:
https://github.com/FrigaZzz/custom-docling-plugins
The plugin extends Docling's image describer to intercept the API response and extract the usage field containing prompt_tokens, completion_tokens, and total_tokens before the pipeline processes it.
The repository includes:
- Custom plugin implementation that captures token metrics
- Setup instructions for integrating with Docling's pipeline
- Examples showing how to access the telemetry data
This lets you track token consumption without modifying Docling's core code. Check the repo for the complete implementation details.
@FrigaZzz veja isso por gentileza.
Grato pelo Retorno
https://github.com/FrigaZzz/custom-docling-plugins/issues/1