# HTTP code 504 from API

**URL:** <https://community.deeplearning.ai/t/http-code-504-from-api/404316>\
**Category:** LangChain for LLM Application Development\
**Created:** [August 1, 2023, 9:48am UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316 "2023-08-01T09:48:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert.Thompson](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/robert.thompson/32/55774_2.png) [@Robert.Thompson](https://community.deeplearning.ai/u/Robert.Thompson)\
**Post date:** [August 1, 2023, 9:48am UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/1 "2023-08-01T09:48:24Z")

</div>

In Question and Answer section, on calling the following code,

```auto
response = llm.call_as_llm(f"{qdocs} Question: Please list all your \
shirts with sun protection in a table in markdown and summarize each one.")

```

I get the following error as of August 1, 2023.

`Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 1.0 seconds as it raised APIError: HTTP code 504 from API 504 Gateway Time-out`

This is the same error as when calling LangChain Chat with Your Data - Document Loading when calling in [22]

`YoutubeAudioLoader APIError: HTTP code 504 from API`

I’ve tried this all all times of data. It used to say rate limit exceeded, now just HTTP 504 a lot.  
Is there a recommended way to use our key, and if so what kind of charges can we expect?

---

<div class="post-metadata">

**Author:** ![s-h-a-m-i-k](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@s-h-a-m-i-k](https://community.deeplearning.ai/u/s-h-a-m-i-k)\
**Post date:** [August 6, 2023, 7:47am UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/2 "2023-08-06T07:47:27Z")

</div>

Getting the same 504 Error, any solutions to this ?

---

<div class="post-metadata">

**Author:** ![Girijesh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/girijesh/32/37283_2.png) [@Girijesh](https://community.deeplearning.ai/u/Girijesh)\
**Post date:** [August 6, 2023, 2:59pm UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/3 "2023-08-06T14:59:55Z")

</div>

Increase the value for request\_timeout parameter, and then try again.  
Please let me know if still face issue(s).

---

<div class="post-metadata">

**Author:** ![Robert.Thompson](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/robert.thompson/32/55774_2.png) [@Robert.Thompson](https://community.deeplearning.ai/u/Robert.Thompson)\
**Post date:** [August 9, 2023, 4:09pm UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/4 "2023-08-09T16:09:36Z")

</div>

> [@Girijesh](#):
>
> request\_timeout

This is now happening further up in [7] VectorstoreIndexCreator.  
As I understand it, request\_timeout can be set in,

```auto
from langchain.chat_models import ChatOpenAI
openai = ChatOpenAI(model_name="gpt-3.5-turbo", request_timeout=8)

```

The model is opened in an external file or in some other way here, how can the request\_timeout be increased here?

Thanks

---

<div class="post-metadata">

**Author:** ![Ed\_Norris](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ed_norris/32/58623_2.png) [@Ed\_Norris](https://community.deeplearning.ai/u/Ed_Norris)\
**Post date:** [August 9, 2023, 5:31pm UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/5 "2023-08-09T17:31:14Z")

</div>

You can always double-check OpenAI’s API status to see if there are larger problems: [https://status.openai.com/](https://status.openai.com/)

Looks like there were problems on 8/3 and 8/1, which might have caused those 504s

---

<div class="post-metadata">

**Author:** ![Girijesh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/girijesh/32/37283_2.png) [@Girijesh](https://community.deeplearning.ai/u/Girijesh)\
**Post date:** [August 9, 2023, 6:37pm UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/6 "2023-08-09T18:37:57Z")

</div>

> [@Robert.Thompson](#):
>
> `openai = ChatOpenAI(model_name="gpt-3.5-turbo", request_timeout=8)`

In your example code snippet  
openai = ChatOpenAI(model\_name=“gpt-3.5-turbo”, request\_timeout=8)

you are instantiating a ChatOpenAI class object with the model name “gpt-3.5-turbo” and a request\_timeout of 8 seconds.  
This means that when you use this object to make API requests to the GPT-3.5 model, each request will have a maximum of 8 seconds to generate a response before it times out.

To increase the request\_timeout, increase it according to your need.  
i.e. request\_timeout=60 or request\_timeout=120

---

<div class="post-metadata">

**Author:** ![Girijesh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/girijesh/32/37283_2.png) [@Girijesh](https://community.deeplearning.ai/u/Girijesh)\
**Post date:** [August 9, 2023, 9:27pm UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/7 "2023-08-09T21:27:15Z")

</div>

Can you please send me your notebook.And let me know the cells that creates a problem.

---

<div class="post-metadata">

**Author:** ![Robert.Thompson](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/robert.thompson/32/55774_2.png) [@Robert.Thompson](https://community.deeplearning.ai/u/Robert.Thompson)\
**Post date:** [August 11, 2023, 6:03pm UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/8 "2023-08-11T18:03:28Z")

</div>

Yes, I read it from your suggestion and looked up where a timeout could be set.

The notebook is the same as each of the following ones, which all result in errors, 2 different courses. Here’s the first which is the one you askeda bout,

1. [LangChain for LLM Application Development: Question and Answer section, Cell [7]](https://learn.deeplearning.ai/langchain/lesson/5/question-and-answer)

```auto
index = VectorstoreIndexCreator(
    vectorstore_cls=DocArrayInMemorySearch
).from_loaders([loader])

```

_Retrying langchain.embeddings.openai.embed\_with\_retry..\_embed\_with\_retry in 4.0 seconds as it raised RateLimitError: exceeded quota for this month._

1. [LangChain Chat with Your Data: Document Loading section, Cell [11]](https://learn.deeplearning.ai/langchain-chat-with-your-data/lesson/2/document-loading)

```auto
url="https://www.youtube.com/watch?v=jGwO_UgTS7I"
save_dir="docs/youtube/"
loader = GenericLoader(
    YoutubeAudioLoader([url],save_dir),
    OpenAIWhisperParser()
)
docs = loader.load()

```

_Extensive error says the following at end: RateLimitError: exceeded quota for this month_

---

<div class="post-metadata">

**Author:** ![Girijesh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/girijesh/32/37283_2.png) [@Girijesh](https://community.deeplearning.ai/u/Girijesh)\
**Post date:** [August 12, 2023, 6:32pm UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/9 "2023-08-12T18:32:07Z")

</div>

Dear Robert,

Please check your plan and billing details. and let me know.

---

<div class="post-metadata">

**Author:** ![Robert.Thompson](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/robert.thompson/32/55774_2.png) [@Robert.Thompson](https://community.deeplearning.ai/u/Robert.Thompson)\
**Post date:** [August 14, 2023, 1:02am UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/10 "2023-08-14T01:02:53Z")

</div>

Girijesh,

I’d be interested to know what you and others are using: Local Jupyter Notebook with VSCode, PyCharm or Google Colab or something else? I’m on macOS.

I’ve been using the deeplearning.ai Notebooks as is so far. Not locally or on Google Colab where I can set OPENAI\_API\_KEY environment variable. That’s how these Short Courses started. Without the need of using our own key.

I’ve seen messages that the Coursera servers were down then up, but it’s not entirely clear here whether we are to download all local files and set an environment variable locally for or use something like Google Colab.

1. I’ve noticed [LangChain for LLM Application Development](https://learn.deeplearning.ai/langchain/lesson/5/question-and-answer) has a .csv file OutdoorClothingCatalog\_1000.csv – it wasn’t possible to open files locally like a .csv file and save it now it is.

2. [LangChain Chat with Your Data](https://learn.deeplearning.ai/langchain-chat-with-your-data/lesson/2/document-loading) is still on one page linking short courses but not on the Forums for discussion.

Again, I’d just be interested to know what you and others are using: Local Jupyter Notebook with VSCode, PyChart (I’m on macOS), or Google Colab or something else?

– Robert

---

<div class="post-metadata">

**Author:** ![Sreedevi\_Gattu](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/sreedevi_gattu/32/58295_2.png) [@Sreedevi\_Gattu](https://community.deeplearning.ai/u/Sreedevi_Gattu)\
**Post date:** [August 14, 2023, 7:09am UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/11 "2023-08-14T07:09:53Z")

</div>

I get the same error inspite of increasing the time out  
**Code**  
`llm = ChatOpenAI(temperature = 0.0, request_timeout=120)`

**Output** of

```auto
response = llm.call_as_llm(f"{qdocs} Question: Please list all your \
shirts with sun protection in a table in markdown and summarize each one.")

```

* * *

Retrying langchain.chat\_models.openai.ChatOpenAI.completion\_with\_retry..\_completion\_with\_retry in 1.0 seconds as it raised APIError: HTTP code 504 from API (

504 Gateway Time-out
# 504 Gateway Time-out
). Retrying langchain.chat\_models.openai.ChatOpenAI.completion\_with\_retry..\_completion\_with\_retry in 2.0 seconds as it raised APIError: HTTP code 504 from API ( 504 Gateway Time-out
# 504 Gateway Time-out
).

---

<div class="post-metadata">

**Author:** ![Robert.Thompson](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/robert.thompson/32/55774_2.png) [@Robert.Thompson](https://community.deeplearning.ai/u/Robert.Thompson)\
**Post date:** [August 14, 2023, 6:20pm UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/12 "2023-08-14T18:20:41Z")

</div>

Hello Sreedevi\_Gattu,

1. Are you using the online notebook where OPENAI\_API\_KEY is stored as local environment variable like in the first Notebook [Models, Prompts and Parsers](https://learn.deeplearning.ai/langchain/lesson/2/models,-prompts-and-parsers) for this short course?

2. If so, do you see the same rate limit error in that section, `[12] get_completion("What is 1+1?")`

3. If not, are you using Google Collab like this article [Fine Tuning Large Language Models with LangChain](https://ai.plainenglish.io/fine-tuning-large-language-models-with-langchain-1cf453349001) and using your own OPENAI\_API\_KEY as it discusses?

4. Or are you using a local install and [Jupyter Notebook and ChatGPT locally](https://medium.com/@c_pzzo/no-fluff-connect-your-jupyter-notebook-with-the-openai-api-and-chatgpt-3-5-github-repo-fa2fdaeb2023)?

Just trying to complete these and move on.

Sincerely,  
Robert D. Thompson

---

<div class="post-metadata">

**Author:** ![iotnerd](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/iotnerd/32/60224_2.png) [@iotnerd](https://community.deeplearning.ai/u/iotnerd)\
**Post date:** [August 15, 2023, 1:45pm UTC](https://community.deeplearning.ai/t/http-code-504-from-api/404316/13 "2023-08-15T13:45:12Z")

</div>

I’ve tried a bunch of different `request_timeout` values, but regardless get the same error doing the course in the embedded notebook ([https://learn.deeplearning.ai/langchain/lesson/5/question-and-answer](https://learn.deeplearning.ai/langchain/lesson/5/question-and-answer)).

 ![image](https://global.discourse-cdn.com/dlai/original/3X/0/5/054f6da642ff321b827e3d9e946b71b64eb2f853.png)
