#Need help connecting ChatGPT to Dall e 2

1 messages · Page 1 of 1 (latest)

valid shore
#

I just receive the error: {'error': {'code': 'invalid_api_key', 'message': "Incorrect API key provided: ''. You can find your API key at https://beta.openai.com.", 'param': None, 'type': 'invalid_request_error'}}

However, this is odd as I am sure I have the correct API key in my code so I'm unsure if it's a syntax error. I even made sure to create a new one, copy and paste it in, receiving the same error.

P.S. This is my first time coding anything at all I know nothing about python I used ChatGTP to code all of this.

import openai
import json
import requests

# Set the API key
openai.api_key = "API key"

# Set the DALL-E 2 endpoint
endpoint = "https://api.openai.com/v1/images/generations"

# Set the default model
model = "image-alpha-001"

# Prompt the user for the prompt
prompt = input("Enter the prompt: ")

# Generate the response using GPT-3
try:
    response = openai.Completion.create(
        engine="text-davinci-002",
        prompt=prompt,
        max_tokens=200,
        n=1,
        stop=None,
        temperature=0.5,
    )
except openai.errors.ApiError as error:
    print(f"An error occurred: {error}")
    exit()

# Set the prompt and model
data = {
    "prompt": response["choices"][0]["text"],
    "model": model,
}

# Send the request to DALL-E 2
try:
    response = requests.post(
        endpoint,
        headers={"Content-Type": "application/json"},
        json=data,
        auth=("API key", ""),
    )
except requests.exceptions.RequestException as error:
    print(f"An error occurred: {error}")
    exit()

# Print the response
print(response.json())