# ERROR: openai.UnprocessableEntityError: Error code: 422

**URL:** <https://discuss.huggingface.co/t/error-openai-unprocessableentityerror-error-code-422/85980>\
**Category:** Beginners\
**Created:** [May 9, 2024, 2:40pm UTC](https://discuss.huggingface.co/t/error-openai-unprocessableentityerror-error-code-422/85980 "2024-05-09T14:40:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![almatkai](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@almatkai](https://discuss.huggingface.co/u/almatkai)\
**Post date:** [May 9, 2024, 2:40pm UTC](https://discuss.huggingface.co/t/error-openai-unprocessableentityerror-error-code-422/85980/1 "2024-05-09T14:40:55Z")

</div>

I ran my custom fine-tuned Mistral 7b Instruct on hf inference and want to use openAI client, so that the API won’t return whole text. Below is settings of api (With TensorFlow it fails to run)

 ![CleanShot 2024-05-09 at 19.14.53@2x](https://us1.discourse-cdn.com/hellohellohello/original/3X/d/c/dc8abc8486516301a140effbed7b4996d48585f8.png)

But now code gives me this error:

```auto
Traceback (most recent call last):
  File "/Users/almatkairatov/Desktop/GENERAL/CreateML training/ML/huggingFace/main.py", line 9, in <module>
    chat_completion = client.chat.completions.create(
  File "/opt/miniconda3/envs/huggingFace/lib/python3.9/site-packages/openai/_utils/_utils.py", line 277, in wrapper
    return func(*args, **kwargs)
  File "/opt/miniconda3/envs/huggingFace/lib/python3.9/site-packages/openai/resources/chat/completions.py", line 590, in create
    return self._post(
  File "/opt/miniconda3/envs/huggingFace/lib/python3.9/site-packages/openai/_base_client.py", line 1240, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
  File "/opt/miniconda3/envs/huggingFace/lib/python3.9/site-packages/openai/_base_client.py", line 921, in request
    return self._request(
  File "/opt/miniconda3/envs/huggingFace/lib/python3.9/site-packages/openai/_base_client.py", line 1020, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.UnprocessableEntityError: Error code: 422 - {'error': 'Template error: template not found', 'error_type': 'template_error'}

```

This code I just take for testing, but as I said it is not working

```auto
import os
from openai import OpenAI

# init the client but point it to TGI
client = OpenAI(
    base_url=os.path.join("https://url.endpoints.huggingface.cloud", "v1/"),
    api_key="API_KEY",
)
chat_completion = client.chat.completions.create(
    model="tgi",
    messages=[
        {"role": "user", "content": "Why is open-source software important?"}
    ],
    stream=True
)

# iterate and print stream
for message in chat_completion:
    print(message.choices[0].delta.content, end="")

```

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [May 9, 2024, 8:38pm UTC](https://discuss.huggingface.co/t/error-openai-unprocessableentityerror-error-code-422/85980/2 "2024-05-09T20:38:29Z")

</div>

Hi,

It looks like no tokenizer\_config.json with a chat template is present. Does your repository contain that? Similar to this line: [https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2/blob/main/tokenizer\_config.json#L42](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2/blob/main/tokenizer_config.json#L42)

---

<div class="post-metadata">

**Author:** ![almatkai](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@almatkai](https://discuss.huggingface.co/u/almatkai)\
**Post date:** [May 9, 2024, 8:51pm UTC](https://discuss.huggingface.co/t/error-openai-unprocessableentityerror-error-code-422/85980/3 "2024-05-09T20:51:18Z")

</div>

yeah, I have found that right before your answer, thank you for your response.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](https://discuss.huggingface.co/u/system)\
**Post date:** [May 10, 2024, 8:51am UTC](https://discuss.huggingface.co/t/error-openai-unprocessableentityerror-error-code-422/85980/4 "2024-05-10T08:51:56Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
