Quickstart¶
1. Create an account and an API key¶
- Sign up at yexapi.com. New accounts receive $0.10 in trial credit, enough for four 1K images.
- Open Console → API Keys (yexapi.com/keys) and
create a key. Keys start with
sk-. - Store the key in an environment variable:
2. Generate an image¶
# pip install openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["YEXAPI_API_KEY"],
base_url="https://api.yexapi.com/v1",
)
result = client.images.generate(
model="gpt-image-2",
prompt="A minimalist poster of a paper boat on calm water",
size="1024x1024",
)
print(result.data[0].url)
// npm install openai (save as quickstart.mjs)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.YEXAPI_API_KEY,
baseURL: "https://api.yexapi.com/v1",
});
const result = await client.images.generate({
model: "gpt-image-2",
prompt: "A minimalist poster of a paper boat on calm water",
size: "1024x1024",
});
console.log(result.data[0].url);
The response contains a link to the image on api.yexapi.com:
{
"created": 1796107749,
"data": [
{ "url": "https://api.yexapi.com/v1/images/files/01M8R5TJAX8YKP68Y851BY595Y/1796107779_9dae96fa.png" }
]
}
Download images you want to keep
Image links stay available for 30 days. Save the file to your own storage if you need it longer.
3. What next¶
- Generating 4K images or many images at once? Use the async endpoint so your HTTP client does not have to wait.
- Learn how
sizeandresolutionmap to output pixels and price.