# Lesson\_2\_Student getting 401 Client Error: Unauthorized for url: https://api.tavily.com/search

**URL:** <https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958>\
**Category:** AI Agents in LangGraph\
**Created:** [January 20, 2025, 7:40am UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958 "2025-01-20T07:40:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![petkao](https://avatars.discourse-cdn.com/v4/letter/p/7bcc69/32.png) [@petkao](https://community.deeplearning.ai/u/petkao)\
**Post date:** [January 20, 2025, 7:40am UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958/1 "2025-01-20T07:40:13Z")

</div>

Using Google Colab.

on the cell:  
tavily\_api\_key=“tavily\_api\_key”

messages = [HumanMessage(content=“What is the weather in sf?”)]

result = abot.graph.invoke({“messages”: messages})

Got:

Calling: {‘name’: ‘tavily\_search\_results\_json’, ‘args’: {‘query’: ‘weather in San Francisco’}, ‘id’: ‘call\_cEb7nvJ0bxAXV2OmCwjEUFd3’, ‘type’: ‘tool\_call’}  
Back to the model!  
Calling: {‘name’: ‘tavily\_search\_results\_json’, ‘args’: {‘query’: ‘weather in San Francisco’}, ‘id’: ‘call\_Ru5wcKggRlF7PBu3XXCR1vHC’, ‘type’: ‘tool\_call’}  
Back to the model!

Then issued int he next cell:  
result

Then no results is return with  
ToolMessage(content=“HTTPError(‘401 Client Error: Unauthorized for url: [https://api.tavily.com/search](https://api.tavily.com/search)’)”, name=‘tavily\_search\_results\_json’, tool\_call\_id=‘call\_cEb7nvJ0bxAXV2OmCwjEUFd3’),

Is it related to tavily\_api\_key?

Thanks.

Peter

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [January 20, 2025, 12:39pm UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958/2 "2025-01-20T12:39:58Z")

</div>

error clearly states there is no authorisation to use api key from the url you have used.

make sure when you running codes locally you have your own api keys and also sometimes when a multi interference api keys is set up, chances are your own openai api key might work. You might need to go through the documentation for the codes you are trying to run for understanding the authorisation part.

---

<div class="post-metadata">

**Author:** ![petkao](https://avatars.discourse-cdn.com/v4/letter/p/7bcc69/32.png) [@petkao](https://community.deeplearning.ai/u/petkao)\
**Post date:** [January 20, 2025, 10:33pm UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958/3 "2025-01-20T22:33:14Z")

</div>

Deepti:

I have included %env TAVILY\_API\_KEY= “tavily\_api\_key” in the previous cell.

But I still got the error.

If I can see the source code from Tavily I can debug it.

Thanks.

Peter

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [January 20, 2025, 10:36pm UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958/4 "2025-01-20T22:36:58Z")

</div>

that’s what is unauthorised for learners to use locally, you need to reach tavily for source code 🤪

---

<div class="post-metadata">

**Author:** ![petkao](https://avatars.discourse-cdn.com/v4/letter/p/7bcc69/32.png) [@petkao](https://community.deeplearning.ai/u/petkao)\
**Post date:** [January 21, 2025, 1:42am UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958/5 "2025-01-21T01:42:53Z")

</div>

Thanks.

Looks like we could not fix this problem even with correct tavily\_api\_key.

Peter

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [January 21, 2025, 1:52am UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958/6 "2025-01-21T01:52:34Z")

</div>

is the tavily api key your account api key from tavily?

---

<div class="post-metadata">

**Author:** ![petkao](https://avatars.discourse-cdn.com/v4/letter/p/7bcc69/32.png) [@petkao](https://community.deeplearning.ai/u/petkao)\
**Post date:** [January 21, 2025, 7:27am UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958/7 "2025-01-21T07:27:38Z")

</div>

Deepti:

The tavily api key I got from Tavily site.

Thanks.

Peter

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [January 21, 2025, 1:46pm UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958/8 "2025-01-21T13:46:20Z")

</div>

oh ok then that should work, can you please post rather screenshot of the error you are encountering, rather than copy paste.

Also did you raise a ticket at tavily site about this error. because seems like the authorisation is blocked from there, probably they will know if there is any issue with your api key.

I also check if in your coded if the API keys are in discrepancy with some other module, even that can cause error.

---

<div class="post-metadata">

**Author:** ![Michela\_Agostini](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/michela_agostini/32/142301_2.png) [@Michela\_Agostini](https://community.deeplearning.ai/u/Michela_Agostini)\
**Post date:** [January 27, 2025, 10:12am UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958/9 "2025-01-27T10:12:18Z")

</div>

I worked locally and I confirm that it works properly 🙂.

My suggestions to solve your issue are the followng :

- From your message, it seems that you are using the **default TAVILY\_API\_KEY**. This should work, however it may have **limited access** and it may only work in specific scenarios. Therefore, my suggestion is to **Generate Your Own TAVILY\_API\_KEY**.

- Another suggestion to solve the problem is to have a look **how you have set up the value of TAVILY\_API\_KEY in the env.** Remember it should be **without quotes** :

TAVILY\_API\_KEY=tvly-your-valid-api-key

Then,

```py
# Load environment variables
load_dotenv()

# Print the API key to verify it is loaded correctly
print(f"TAVILY_API_KEY: {os.getenv('TAVILY_API_KEY')}")

```

Remember it should be appear without quotes!

Hoping this could help you!

---

<div class="post-metadata">

**Author:** ![petkao](https://avatars.discourse-cdn.com/v4/letter/p/7bcc69/32.png) [@petkao](https://community.deeplearning.ai/u/petkao)\
**Post date:** [January 27, 2025, 6:54pm UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958/10 "2025-01-27T18:54:10Z")

</div>

Michela:

Thanks for your help.

I created a new TAVILY\_API\_KEY, and it worked. After one day, it did not work again.

I do not know what the actual variable name. Like openai\_api\_key I can just give the key variable directly and it worked.

I was able to print TAVILY\_API\_KEY.

I did use quotes around TAVILY\_API\_KEY. I am going to try without the quotes.

Thanks again.

The journey to learn how to create AI agents is not easy. I am going to try n8n also.

Tzechung Kao (Peter)

---

<div class="post-metadata">

**Author:** ![Michela\_Agostini](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/michela_agostini/32/142301_2.png) [@Michela\_Agostini](https://community.deeplearning.ai/u/Michela_Agostini)\
**Post date:** [January 27, 2025, 7:58pm UTC](https://community.deeplearning.ai/t/lesson-2-student-getting-401-client-error-unauthorized-for-url-https-api-tavily-com-search/754958/11 "2025-01-27T19:58:23Z")

</div>

Step by step! Please, continue to keep up-to-dated about this topic. Glad to share insights together to solve asap the issue.
