Problem with my API KEY chatgpt (using st.secrets)

Good afternoon everyone,

I need some help so i try to access my chatgpt api using the secret key option directly in my streamlit app i’ve added manually the variable with my key.
However, it’s impossible to get some thing i have the same error message (impossible to process my request at this time).
Normaly, i writed correctly i tried many option and combinaison but i m getting the same issue:

import openai
import json
import requests
import streamlit as st
import os


impossible to connect with my chat gpt API.

Thank you very much for your help


1 Like

Hi @Amr_Lgh,

Thanks for posting!

Can you share the full error message you’re getting on your end?


thank you for your answer.
I removed my api key. The problem is that i don’t really have an error I mean he cannot get an access to chat gpt and localy it works perfectly this is what i have :

The problem is to connect my api key with my project i thhink i did correctly because i followed your great tutorial.

Thank you very much for your help

Can you share the repo with your code so I can better troubleshoot the issue for you?

1 Like

Hey @tonykip ,

of course :

Thank you for your help :slight_smile:

1 Like

this is the link for my repo:
repo git


Someone to assist me please ?

Thank you very much :slight_smile:

Thanks for sharing, will take a look.

1 Like

So you’re missing the secrets.toml file that should contain your API key. I would advise against using .env which exposes your API key in your commit to GitHub; security risk.

Here’s what you should do instead:

  1. In your root directory, create the file .streamlit/secrets.toml
  2. Paste your API key inside the secrets.toml file and save
  3. In the root folder, create a file named .gitignore and add this path to the file .streamlit/secrets.toml (this will ensure your API key is not deployed to GitHub)

Here’s a more detailed guide on how to manage your secrets.

1 Like

Thanks for sharing this.

Hey @tonykip ,

Thank you very much for your time !

Hey @tonykip ,
I will try your solution and let you know.

Thanks again for your time and patience :slight_smile:

1 Like

Cool! Let us know if this worked.


Hey @tonykip
I hope you are doing great ?

In my side, I tried many times, I follow also your link and this one:

But each time I get an email from openai which told me that my api is disabled.
I try like you said and I also try by adding a variable name inside toml but it doesn’t work. Same Issue.

(key is disabled no worry :slight_smile: )

I need some help please and thank you very much for it.

My repo:

thank you again


The .toml file needs to be structured like so:

key_var = 123456789

Key can be retrieved using the following based on structure above:


Please let me know if you have questions. Thank you

1 Like

Thanks for the details. Try using this format to get the key from your secrets file:

openai.api_key = st.secrets["openai_api"]

I created a pull request for your repo above. You can merge it and try it out.

1 Like

Good afternoon @REPNOT , @tonykip

I tried both of your solution but it still doesn’t work for me.
I have immediately a message from openai that told me my key has been disabled…

Thank you very much for your help :slight_smile:
I’m little bit desesperated with this issue…

Best regards,

I think it’s a problem linked to the .gitignore file because when i change the api key i received in a second an email from openai.

The OpenAI API key is in secrets.toml.

1 Like