Open
Description
Describe the bug
Sometimes when using the openrouter API endpoint with the OpenAIServerModel
you will get the following error:
Error in generating model output:
'NoneType' object has no attribute 'prompt_tokens'
This is because openrouter doesn't guarantee the usage
key.
Here is the openrouter API page: https://openrouter.ai/docs/api-reference/overview#completionsresponse-format
Here is the openapi page: https://platform.openai.com/docs/api-reference/chat/object
Code to reproduce the error
Use the openrouter API endpoint with the OpenAIServerModel, occasionally this error will materialize.
Error logs (if any)
Error in generating model output:
'NoneType' object has no attribute 'prompt_tokens'
Expected behavior
Defaults to 0
when response.usage
is None.
Packages version:
smolagents 1.17.0
Additional context
Add any other context about the problem here.