typesecret
{
"aspect_ratio": "3:2",
"background": "auto",
"moderation": "auto",
"number_of_images": 2,
"openai_api_key": "[REDACTED]",
"output_compression": 90,
"output_format": "webp",
"prompt": "<today's date>",
"quality": "auto"
}npm install replicate
REPLICATE_API_TOKEN environment variable:export REPLICATE_API_TOKEN=r8_3wK**********************************
This is your API token. Keep it to yourself.
import Replicate from "replicate";
import fs from "node:fs";
const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN,
});
Run openai/gpt-image-1 using Replicate’s API. Check out the model's schema for an overview of inputs and outputs.
const input = {
aspect_ratio: "3:2",
background: "auto",
moderation: "auto",
number_of_images: 2,
openai_api_key: "[REDACTED]",
output_compression: 90,
output_format: "webp",
prompt: "<today's date>",
quality: "auto"
};
const output = await replicate.run("openai/gpt-image-1", { input });
// To access the file URL:
console.log(output[0].url()); //=> "http://example.com"
// To write the file to disk:
fs.writeFile("my-image.png", output[0]);
To learn more, take a look at the guide on getting started with Node.js.
pip install replicate
REPLICATE_API_TOKEN environment variable:export REPLICATE_API_TOKEN=r8_3wK**********************************
This is your API token. Keep it to yourself.
import replicate
Run openai/gpt-image-1 using Replicate’s API. Check out the model's schema for an overview of inputs and outputs.
output = replicate.run(
"openai/gpt-image-1",
input={
"aspect_ratio": "3:2",
"background": "auto",
"moderation": "auto",
"number_of_images": 2,
"openai_api_key": "[REDACTED]",
"output_compression": 90,
"output_format": "webp",
"prompt": "<today's date>",
"quality": "auto"
}
)
# To access the file URL:
print(output[0].url())
#=> "http://example.com"
# To write the file to disk:
with open("my-image.png", "wb") as file:
file.write(output[0].read())
To learn more, take a look at the guide on getting started with Python.
REPLICATE_API_TOKEN environment variable:export REPLICATE_API_TOKEN=r8_3wK**********************************
This is your API token. Keep it to yourself.
Run openai/gpt-image-1 using Replicate’s API. Check out the model's schema for an overview of inputs and outputs.
curl -s -X POST \
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \
-H "Content-Type: application/json" \
-H "Prefer: wait" \
-d $'{
"input": {
"aspect_ratio": "3:2",
"background": "auto",
"moderation": "auto",
"number_of_images": 2,
"openai_api_key": "[REDACTED]",
"output_compression": 90,
"output_format": "webp",
"prompt": "<today\'s date>",
"quality": "auto"
}
}' \
https://api.replicate.com/v1/models/openai/gpt-image-1/predictions
To learn more, take a look at Replicate’s HTTP API reference docs.
{
"id": "66fb5tq3n9rma0cpfkvs4ay9sm",
"model": "openai/gpt-image-1",
"version": "hidden",
"input": {
"aspect_ratio": "3:2",
"background": "auto",
"moderation": "auto",
"number_of_images": 2,
"openai_api_key": "[REDACTED]",
"output_compression": 90,
"output_format": "webp",
"prompt": "<today's date>",
"quality": "auto"
},
"logs": "Generating image...\nGenerated image in 41.3sec\nGenerated 2 images\nInput text token count: 22\nInput image token count: 0\nOutput token count: 12416",
"output": [
"https://replicate.delivery/xezq/kLpDUd3t3QbeYihLSVGRlmIeebO9kRISAvfH5FXkTTldcTdSB/tmprgna8b0p.png",
"https://replicate.delivery/xezq/OLLpcrXif9X1ekJvoJQxv5CWVKoftOq86Ve5Y1QeZei4xN1JF/tmpwt2u9o48.png"
],
"data_removed": false,
"error": null,
"source": "web",
"status": "succeeded",
"created_at": "2025-04-28T15:15:42.634Z",
"started_at": "2025-04-28T15:15:42.642121Z",
"completed_at": "2025-04-28T15:16:23.911192Z",
"urls": {
"cancel": "https://api.replicate.com/v1/predictions/66fb5tq3n9rma0cpfkvs4ay9sm/cancel",
"get": "https://api.replicate.com/v1/predictions/66fb5tq3n9rma0cpfkvs4ay9sm",
"stream": "https://stream.replicate.com/v1/files/bcwr-hwwqawsdbnd4ywq6667rcugpdevsuxahojaafd7inj6zusves6xa",
"web": "https://replicate.com/p/66fb5tq3n9rma0cpfkvs4ay9sm"
},
"metrics": {
"image_count": 2,
"predict_time": 41.269070912,
"total_time": 41.277192
}
}
