# Error in generating model output: InferenceClient.chat\_completion() got an unexpected keyword argument 'last\_input\_token\_count'

**URL:** <https://discuss.huggingface.co/t/error-in-generating-model-output-inferenceclient-chat-completion-got-an-unexpected-keyword-argument-last-input-token-count/157962>\
**Category:** Models\
**Created:** [June 4, 2025, 10:05am UTC](https://discuss.huggingface.co/t/error-in-generating-model-output-inferenceclient-chat-completion-got-an-unexpected-keyword-argument-last-input-token-count/157962 "2025-06-04T10:05:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MShijas](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mshijas/32/48780_2.png) [@MShijas](https://discuss.huggingface.co/u/MShijas)\
**Post date:** [June 4, 2025, 10:05am UTC](https://discuss.huggingface.co/t/error-in-generating-model-output-inferenceclient-chat-completion-got-an-unexpected-keyword-argument-last-input-token-count/157962/1 "2025-06-04T10:05:51Z")

</div>

from smolagents import CodeAgent, InferenceClientModel

agent = CodeAgent(tools=, model=model)

alfred\_agent = agent.from\_hub(‘sergiopaniego/AlfredAgent’, token=hf\_token, trust\_remote\_code=True)

alfred\_agent.run(“Give me best playlist for a party at the Wayne’s mansion. The party idea is a ‘villain masquerade’ theme”)

In the above code I am using a llm model from openai in the agent instead of the Qwen model, but in the alfred\_agent I am using the default hugging face provided model. When running the code I am getting an error saying "AgentGenerationError: Error in generating model output:  
InferenceClient.chat\_completion() got an unexpected keyword argument ‘last\_input\_token\_count’  
" and “TypeError: InferenceClient.chat\_completion() got an unexpected keyword argument ‘last\_input\_token\_count’”.

What can I do so that I can use gpt model for the llm part (usage limit with the model provided by hugginface). Can I use the agent provide by the huggingface without any issue or is there any other solution.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [June 4, 2025, 12:26pm UTC](https://discuss.huggingface.co/t/error-in-generating-model-output-inferenceclient-chat-completion-got-an-unexpected-keyword-argument-last-input-token-count/157962/2 "2025-06-04T12:26:16Z")

</div>

For example, if you want to use OpenAI’s LLM, I think you need to use `OpenAIServerModel` instead of `InferenceClientModel`.

> **[Models](https://huggingface.co/docs/smolagents/reference/models#smolagents.OpenAIServerModel)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

Maybe like this.

```py
from smolagents import CodeAgent, OpenAIServerModel

model = OpenAIServerModel(model_id="gpt-4o", api_base="https://api.openai.com/v1", api_key=os.getenv("OPENAI_API_KEY", None))
agent = CodeAgent(tools=[], model=model)

```

---

<div class="post-metadata">

**Author:** ![Pimpcat-AU](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/pimpcat-au/32/48989_2.png) [@Pimpcat-AU](https://discuss.huggingface.co/u/Pimpcat-AU)\
**Post date:** [June 10, 2025, 7:58pm UTC](https://discuss.huggingface.co/t/error-in-generating-model-output-inferenceclient-chat-completion-got-an-unexpected-keyword-argument-last-input-token-count/157962/3 "2025-06-10T19:58:03Z")

</div>

llm = HuggingFaceEndpoint(  
repo\_id=huggingface\_repo\_id,  
temperature=0.5,  
model\_kwargs={}, # do not use “max\_length” here  
)

# If you need to set output length, use “max\_new\_tokens” or the official config method.

Solution provided by Triskel Data Deterministic AI.
