# TypeError: InferenceClient.text\_generation() got an unexpected keyword argument

**URL:** <https://discuss.huggingface.co/t/typeerror-inferenceclient-text-generation-got-an-unexpected-keyword-argument/160999>\
**Category:** Beginners\
**Created:** [June 28, 2025, 10:28am UTC](https://discuss.huggingface.co/t/typeerror-inferenceclient-text-generation-got-an-unexpected-keyword-argument/160999 "2025-06-28T10:28:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adi4314](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@adi4314](https://discuss.huggingface.co/u/adi4314)\
**Post date:** [June 28, 2025, 10:28am UTC](https://discuss.huggingface.co/t/typeerror-inferenceclient-text-generation-got-an-unexpected-keyword-argument/160999/1 "2025-06-28T10:28:36Z")

</div>

repo\_id=“mistralai/Mistral-7B-Instruct-v0.3”

llm=HuggingFaceEndpoint(repo\_id=repo\_id,max\_length=150,temperature=0.7,token=os.getenv(“HF\_TOKEN”))

llm.invoke(“What is machine learning”)

error :  
TypeError: InferenceClient.text\_generation() got an unexpected keyword argument ‘max\_length’

IDK how to fix this. I’ve tried everthing. its just not working.

---

<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 28, 2025, 11:55am UTC](https://discuss.huggingface.co/t/typeerror-inferenceclient-text-generation-got-an-unexpected-keyword-argument/160999/2 "2025-06-28T11:55:31Z")

</div>

Try:

```py
#llm=HuggingFaceEndpoint(repo_id=repo_id,max_length=150,temperature=0.7,token=os.getenv("HF_TOKEN"))
llm=HuggingFaceEndpoint(repo_id=repo_id,max_new_tokens=150,temperature=0.7,token=os.getenv("HF_TOKEN"))

```

> [@TypeError: InferenceClient.text\_generation() got an unexpected keyword argument 'token'](https://discuss.huggingface.co/t/typeerror-inferenceclient-text-generation-got-an-unexpected-keyword-argument-token/158815):
>
> ##########################Code##################################### import os from langchain\_huggingface import HuggingFaceEndpoint from langchain\_core.prompts import PromptTemplate from langchain.chains import RetrievalQA from langchain\_huggingface import HuggingFaceEmbeddings from langchain\_community.vectorstores import FAISS from langchain\_community.document\_loaders import PyPDFLoader, DirectoryLoader Step 1: Setup LLM (Mistral with HuggingFace) HF\_TOKEN=os.environ.get(“HF\_TOKEN”) HU…
