#dall-e api!

24 messages · Page 1 of 1 (latest)

rugged depot
#

hello! i made a super simple server side web app for a larger project and my implementation depends on the DALL-E API. Generated a key, dropped that in my .env, used Node.js and Heroku to run the server. The server works fine but my code is failing to access the API itself. Anyone know how to troubleshoot? I'm new to basically all of this. Here is my server.js code, which is calling the API. ```const express = require('express');
const cors = require('cors');
const axios = require('axios');
const dotenv = require('dotenv');

dotenv.config();

const app = express();
app.use(cors());
app.use(express.json());
app.use(express.static('public'));

app.post('/generate-image', async (req, res) => {
const dreamDescription = req.body.dreamDescription;
const response = await callDalleAPI(dreamDescription);
res.send(response.data);
});

async function callDalleAPI(prompt) {
const apiEndpoint = 'https://api.openai.com/v1/images/generations';
const headers = {
'Content-Type': 'application/json',
'Authorization': Bearer ${process.env.DALLE_API_KEY},
};

const body = {
model: 'image-alpha-001',
prompt: prompt,
num_images: 1,
size: '1024x1024',
response_format: 'url',
};

try {
const response = await axios.post(apiEndpoint, body, { headers });
return response.data;
} catch (error) {
console.error('Error calling DALL-E API:', error.response ? error.response.data : error);
if (error.response) {
console.error('Error status:', error.response.status);
console.error('Error headers:', error.response.headers);
}
return { error: 'Failed to generate image' };
}
}

const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(Server running at http://localhost:${port});
});

final hawk
#

Why not using the openai module? ```const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const response = await openai.createImage({
prompt: "A cute baby sea otter",
n: 2,
size: "1024x1024",
});

primal compass
#

image-alpha-001 doesnt exist

#

use the image generation endpoints

rugged depot
#

@primal compass @final hawk This helped! But I'm now getting this error where it says I've reaching the billing limit. I'm using the free trial and haven't used any of the $18 at all. Any clue what's up?

#
2023-04-20T22:23:05.699567+00:00 app[web.1]: Error calling DALL-E API: {
2023-04-20T22:23:05.699588+00:00 app[web.1]: error: {
2023-04-20T22:23:05.699589+00:00 app[web.1]: code: 'billing_hard_limit_reached',
2023-04-20T22:23:05.699591+00:00 app[web.1]: message: 'Billing hard limit has been reached',
2023-04-20T22:23:05.699592+00:00 app[web.1]: param: null,
2023-04-20T22:23:05.699593+00:00 app[web.1]: type: 'invalid_request_error'
2023-04-20T22:23:05.699593+00:00 app[web.1]: }
2023-04-20T22:23:05.699593+00:00 app[web.1]: }
2023-04-20T22:23:05.699610+00:00 app[web.1]:``` etc....
#

Thank you so much for the previous debug! Realized I also wasn't updating my web app via Git.

final hawk
rugged depot
final hawk
#

then, export OPENAI_API_KEY="<OPENAI_API_KEY>"

#

then

#

openai api completions.create -m ada -p "why the sky is blue?"

#

if you get an answer then it means you have everything in your account correct

rugged depot
#

Realizing what my issue might be -- I have my API key in a .env as DALLE_API_KEY="<APIKEY>". Do I need it specifically saved as OPENAI_API_KEY?

final hawk
#

yes the environment variable is actually OPENAI_API_KEY

#

but you can test it first with the above and if that is right then everything else should

rugged depot
#

again receiving Error: You exceeded your current quota, please check your plan and billing details. (HTTP status code: 429)

final hawk
#

Yeah you have to check your billing preferences and see if there is a limit or something in place

rugged depot
#

I'm checking my settings, but I don't even have any billing info set up because I'm on the free trial still (just started this morning)

#

I just signed up for the paid account, and it's working!

final hawk
#

Hmm interesting, but it will still consume your free credits i would assume?