Skip to main content
POST
cURL
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를 전달하세요.
페이지 오른쪽의 Playground에서 Authorization 및 request body를 입력한 다음 https://bettertoken.ai/v1/images/generations로 request를 직접 보낼 수 있습니다.
API keys를 frontend browser code, Git repositories, tickets, screenshots 또는 logs에 넣지 마세요. server-side proxy calls에서는 API keys를 server environment variables 또는 secret manager에만 저장하세요.

알맞은 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를 명시적으로 보내세요.
여러 independent requests를 보내 여러 images를 생성하세요. 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)

JPEG 또는 WebP files를 직접 받기 위해 output_format: "jpeg" 또는 output_format: "webp"에 의존하지 마세요. 현재 endpoint는 여전히 PNG image content를 반환할 수 있습니다. product에 JPEG 또는 WebP가 필요하면 먼저 PNG를 받은 후 자체 code에서 변환하세요.

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에 몇 분을 허용합니다.

관련 문서

인증

Authorization
string
header
필수

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

본문

application/json
model
enum<string>
기본값:gpt-image-2
필수

Use the GPT Image 2 model ID.

사용 가능한 옵션:
gpt-image-2
예시:

"gpt-image-2"

prompt
string
필수

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."

n
기본값:1

Use 1. Send separate requests when you need multiple output images.

예시:

1

size
enum<string>
기본값:1024x1024

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"

response_format
enum<string>
기본값:b64_json

Use b64_json.

사용 가능한 옵션:
b64_json
예시:

"b64_json"

output_format
enum<string>
기본값:png

Use png. Do not rely on jpeg or webp being returned directly in the selected format.

사용 가능한 옵션:
png
예시:

"png"

응답

Image generation result.