이미지 생성 API
GPT Image 2와 BetterToken의 OpenAI-compatible API로 text에서 이미지를 생성하세요. API Key, Base URL, parameters, Python, JavaScript 및 errors를 안내합니다.
POST /v1/images/generations
text-to-image endpoint는 application/json request body를 사용합니다. prompt를 제출하고 HTTP request를 열어 둔 뒤 같은 response의 data[0].b64_json에서 생성된 이미지를 읽으세요.
https://bettertoken.ai/v1을 Base URL로 사용하세요. Authorization: Bearer YOUR_API_KEY를 통해 BetterToken API Key를 전달하세요.알맞은 workflow 선택
- 텍스트로 이미지를 생성하고 결과 저장: 이 페이지를 계속 사용하세요.
curl예제로 시작한 다음 이미지 저장에서data[0].b64_json을 decode하세요. - 기존 이미지 편집: 하나 이상의 source file을
multipart/form-data로 보내는 Image to image를 사용하세요. - 모델과 parameters를 선택하고 budget 추정: 현재 Model ID와 가격은 모델 광장에서 확인하고 request parameters는 아래 권장 값을 참고하세요. 전체 request-response 흐름은 영문 GPT Image 2 첫 요청 문서에서 확인할 수 있습니다.
curl 빠른 시작
https://bettertoken.ai/v1을 Base URL로 사용하고 https://bettertoken.ai/v1/images/generations로 request를 보내세요.
권장 값
모든 request에서 다음 fields를 명시적으로 보내세요.n > 1인 단일 request에 의존하지 마세요.
권장 sizes
size는 예상 aspect ratio와 size tier를 나타냅니다. 실제 반환 pixels는 server에 의해 mapping 또는 adjusted될 수 있습니다. output을 요청한 값으로 강제로 crop하지 말고 decoded image dimensions를 사용하세요.
이미지 저장
성공한 response는 다음 OpenAI-compatible image response shape를 따릅니다.data[0].b64_json을 읽어 base64 image content로 저장하세요. response에는 revised_prompt 등의 extra fields가 포함될 수 있으므로 client에서 이 fields를 허용하세요.
항상 output_format: "png"를 설정하세요. 그런 다음 file headers를 검사하지 않고 decoded image를 .png로 저장하세요.
JavaScript 예시(Node.js)
Response flow
이 endpoint는 synchronous입니다.POST /images/generations를 보낸 후 server가 response할 때까지 현재 HTTP request를 열어 두세요. generation에 성공하면 image content가 data[0].b64_json으로 반환됩니다.
endpoint는 task_id를 반환하지 않으며 별도의 status query 또는 result download endpoint가 없습니다.
Timeouts 및 retries
- HTTP client timeouts를 몇 분으로 설정하세요.
- transport errors,
408,409,425,429및5xx는 retry하세요. 400,401, missing parameters 또는 malformed requests는 자동 retry하지 마세요.3s,8s,15s등의 exponential backoff를 사용하세요.- duplicate images를 허용할 수 없다면 retry하기 전에 자체 request ID를 기록하세요.
Error handling
errors는 일반적으로 JSON을 반환합니다. error를 표시할 때는error.message를 먼저 읽고 message, HTTP status text 순서로 읽으세요.
Integration checklist
- Base URL은
https://bettertoken.ai/v1입니다. - header에는
Authorization: Bearer YOUR_API_KEY가 포함됩니다. - request는
application/json과POST /images/generations를 사용합니다. model은gpt-image-2,response_format은b64_json,output_format은png,n은1입니다.size는1024x1024등의 권장 값 중 하나입니다.- HTTP client가 generation에 몇 분을 허용합니다.
관련 문서
인증
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
본문
Use the GPT Image 2 model ID.
gpt-image-2 "gpt-image-2"
A detailed description of the image to generate.
"A futuristic AI product poster on a light background, with glass textures, a clean composition, and a premium technology aesthetic."
Use 1. Send separate requests when you need multiple output images.
1
The requested image size or aspect-ratio tier. The server may map or adjust the final pixel dimensions, so inspect the decoded image for its actual size.
auto, 1024x1024, 1536x1024, 1024x1536, 1536x1152, 1152x1536, 2048x2048, 2048x1152, 3840x2160, 2160x3840 "1024x1024"
Use b64_json.
b64_json "b64_json"
Use png. Do not rely on jpeg or webp being returned directly in the selected format.
png "png"
응답
Image generation result.

