I’m trying to create an image variant using the example code (node.js) from the API reference docs: (I can’t include a link to the docs here)
Here is the exact code I’m using:
import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI({apiKey: 'my-api-key-here'});
async function main() {
const image = await openai.images.createVariation({
image: fs.createReadStream("./.tmp/tmp.png"),
});
console.log(image.data);
}
main();
I consistently get a generic Connection Error from openai. Here is the output of running this simple program:
miketorra@Mikes-MacBook-Pro server % node ./OAITEST.js
(node:2522) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
file:///Users/miketorra/x6/hawk-web/server/node_modules/openai/core.mjs:285
throw new APIConnectionError({ cause: response });
^
APIConnectionError: Connection error.
at OpenAI.makeRequest (file:///Users/miketorra/x6/hawk-web/server/node_modules/openai/core.mjs:285:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async main (file:///Users/miketorra/x6/hawk-web/server/OAITEST.js:7:17) {
status: undefined,
headers: undefined,
error: undefined,
code: undefined,
param: undefined,
type: undefined,
cause: FetchError: request to https://api.openai.com/v1/images/variations failed, reason: read ECONNRESET
at ClientRequest.<anonymous> (/Users/miketorra/x6/hawk-web/server/node_modules/node-fetch/lib/index.js:1501:11)
at ClientRequest.emit (node:events:519:28)
at TLSSocket.socketErrorListener (node:_http_client:495:9)
at TLSSocket.emit (node:events:531:35)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET'
}
}
Node.js v21.5.0
I’ve tried making sure the image fits all the criteria outlined here: (I can’t include a link to the post here, but it’s on the OpenAI community forum titled “bug-error-413-the-data-value-transmitted-exceeds-the-capacity-limit-when-calling-v1-images-edits”). I’ve tried different images of different sizes. I haven’t been able to get this API call to work, but I’m using the exact example from the docs (except of course I don’t have a ‘known good’ image to use as input, other than knowing that it works when I ask ChatGPT to create a variant, which I’m aware is different).
Is there a functioning example of how to generate an image variant via API?