Tried to add an api key to ~/.bashrc

I put theexport OPENAI_API_KEY="your_api_key_here"
Then I tried to run a script for ChatGPT (CLI) in the terminal. I got an error code and renewed the key i ~/.bashrc. When I tried to source I got a message: Sample: command not found

I tired to restart the terminal, but no it says Sample: kommando ikke funnet dagr@opensuse22:~>
I must have done something really wrong here. Can somebody help me to put the api key in ~/.bashrc and get rid of the sample message?

Dag R

what kind of script do you have? I use alias (made by chatgpt), it looks like that:

my API key is defined like yours… idk if this can help you

export OPENAI_API_KEY="your-api-key"

alias gpt='function _chatgpt() {
  response=$(curl -s https://api.openai.com/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -d "{
      \"model\": \"gpt-4o-mini\",
      \"messages\": [
        {
          \"role\": \"system\",
          \"content\": \"za računanje uporabi python knjižnice, za odgovore uporabi slovenščino, za valute uporabi EUR in znak €, za odgovore porabi do največ 250 znakov, bodi zelo kratek v odgovorih\"
        },
        {
          \"role\": \"user\",
          \"content\": \"$*\"
        }
      ]
    }")
  echo $response | jq -r .choices[0].message.content
}; _chatgpt'

Usage: gpt “your prompt” or gpt your prompt, change role content to your liking,
put alias into .bashrc somewhere

I saw I had removed the hash in the first line of the ~/.bashrc. I commented out the line and the Sample disappeared when I used the terminal.

Dag R

I tried to use the simple curl command:

curl https://api.openai.com/v1/chat/completions
-H “Authorization: Bearer $OPENAI_API_KEY”
-H “Content-Type: application/json”
-d ‘{
“model”: “gpt-4”,
“messages”: [{“role”: “user”, “content”: “Hello, ChatGPT!”}]
}’"

I got an error message “quota exceeded”. There is no problem with my account and I’m in the beginning of payment periode, so I tried to renew the api key.

Dag R

change gpt-4 to gpt-4o, maybe you exceeded your hourly quota for gpt-4? idk really…

I had put the api key in ~/.bashrc without quotes signs in both ends of the key. When I realized my mistake it was easy to fix. Thank for support!

Dag Ringdal
92858644

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.