ConnectionError when creating the vector_index using OpenAiEmbedding model

here is the error I get:
WARNING:llama_index.embeddings.openai.utils:Retrying llama_index.embeddings.openai.base.get_embeddings in 0.4225984022196171 seconds as it raised APIConnectionError: Connection error…


LocalProtocolError Traceback (most recent call last)

/usr/local/lib/python3.10/dist-packages/httpx/_transports/default.py in map_httpcore_exceptions() 68 try: —> 69 yield 70 except Exception as exc:


60 frames

LocalProtocolError: Illegal header value b’Bearer ’

The above exception was the direct cause of the following exception:

LocalProtocolError Traceback (most recent call last)

LocalProtocolError: Illegal header value b’Bearer ’

The above exception was the direct cause of the following exception:

APIConnectionError Traceback (most recent call last)

/usr/local/lib/python3.10/dist-packages/openai/_base_client.py in _request(self, cast_to, options, remaining_retries, stream, stream_cls) 984 985 log.debug(“Raising connection error”) → 986 raise APIConnectionError(request=request) from err 987 988 log.debug(

APIConnectionError: Connection error.

I cannot understand what goes wrong here. The summary_index works just fine. Any ideas?

You are doing the assignment in your local jupyter then you would require your own OpenAPI Key

I added
import openai

it helped

1 Like

Hello,
I have the same problem when trying to run it locally !! how have you done ?
Thanks in advance.

I have already added my personal OpenAI Key of course but still have the same problem

I’m also running into the same problem trying to run this on replit.

Where do i input my own api key into this function?
Also do I need the code for helper.py?
openai.api_key = get_openai_api_key()

I get the same issue, in a colab jupyter notebook, even though I have entered my openai api key.
any solution or thought?
many thanks,

you have to create a .txt file in the root of the project directory. and save it as .env.txt in which the api key should be stored as OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. You might also have to add it in you system’s local environment variables.