# Smolagents 401 cliennt error

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsmolagents-401-cliennt-error%2F139978%3E%5C
**Category:** Beginners\
**Created:** [February 10, 2025, 9:06am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsmolagents-401-cliennt-error%2F139978 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fyug-sinha02)%5C
**Post date:** [February 10, 2025, 9:06am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsmolagents-401-cliennt-error%2F139978%2F1 "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: [/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2FQwen%2FQwen2.5-Coder-32B-Instruct%2Fv1%2Fchat%2Fcompletions%5D(https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2FQwen%2FQwen2.5-Coder-32B-Instruct%2Fv1%2Fchat%2Fcompletions) (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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [February 10, 2025, 9:24am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsmolagents-401-cliennt-error%2F139978%2F2 "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.
