# Smolagents 401 cliennt error

**URL:** <https://discuss.huggingface.co/t/smolagents-401-cliennt-error/139978>\
**Category:** Beginners\
**Created:** [February 10, 2025, 9:06am UTC](https://discuss.huggingface.co/t/smolagents-401-cliennt-error/139978 "2025-02-10T09:06:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yug-sinha02](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/yug-sinha02/32/40811_2.png) [@yug-sinha02](https://discuss.huggingface.co/u/yug-sinha02)\
**Post date:** [February 10, 2025, 9:06am UTC](https://discuss.huggingface.co/t/smolagents-401-cliennt-error/139978/1 "2025-02-10T09:06:38Z")

</div>

from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel  
model = HfApiModel(token=“my\_acces\_token”)  
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)  
agent.run(“Who won the t20 worldcup 2024”)

# I am trying to run the above code and this is the error that i am getting

Error in generating model output:  
401 Client Error: Unauthorized for url: [https://api-inference.huggingface.co/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions](https://api-inference.huggingface.co/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions) (Request ID: yW7h4j)

401 Unauthorized

whereas i saw multiple users using the exact same code and making this work for themselves

---

<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:** [February 10, 2025, 9:24am UTC](https://discuss.huggingface.co/t/smolagents-401-cliennt-error/139978/2 "2025-02-10T09:24:41Z")

</div>

The contents of the token probably do not correspond to Inference. If you do not pass the token, that code will work normally.

> **[User access tokens](https://huggingface.co/docs/hub/security-tokens)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.
