Most image models can be called through the two OpenAI-compatible endpoints: text-to-image
POST /v1/images/generations and image editing POST /v1/images/edits. Use the official OpenAI SDK and point base_url to https://api.ephone.ai/v1.Text to image
b64_json truncated):
Edit images
Send one or more images with a prompt to restyle, replace elements or composite several inputs; add amask to repaint only its transparent area. Images are uploaded as a multipart form; use the field name image[] for multiple images (the official SDK handles this when you pass a list).
Streaming partial images
The gpt-image family (gpt-image-2.5-sunburst, gpt-image-2.5-flare, gpt-image-2, gpt-image-1.5, gpt-image-1, …) supports streaming: pass stream: true to receive 0–3 partial images while the image is being generated, followed by the final image. Useful for showing users a rough preview early.
The response is a stream of server-sent events; each event’s
type matches its event: line:
image_generation.partial_image: a partial image (image_edit.partial_imageon the edit endpoint);partial_image_indexstarts at 0image_generation.completed: the final image (image_edit.completedon the edit endpoint), carrying the request’susageerror: something failed mid-stream, see below
stream=True, partial_images=2 to client.images.edit(...) in Python, or -F stream=true -F partial_images=2 with cURL; the event names become image_edit.*.
Raw event stream (b64_json truncated):
Billing
- Each partial image consumes some extra image output tokens (the amount depends on size and quality). They are already included in the
usageof thecompletedevent and billed at actual usage, with no separate fee. Setpartial_imagesto 0 if you don’t need previews. - Requests that fail before the final image is delivered are not billed.
- If the client disconnects mid-stream, the image is still generated and billed as usual.
Errors
- Before streaming starts (invalid parameters, insufficient balance, content moderation, …): you get an HTTP error status and a JSON error body, exactly as without streaming.
- During streaming (after partial images have been sent): the stream ends with an
errorevent; the HTTP status is already 200 at that point. The official SDK raisesAPIErrorwhile iterating, so wrap the whole loop intry:
Notes
- Partial images are only produced for single-image requests. With
ngreater than 1, each final image arrives as its owncompletedevent andusage(the total for all images) is attached to the last one. - Other models accept
stream: truetoo: there are no partial images, and a singlecompletedevent arrives once the image is ready, so your code doesn’t need to special-case models. - When streaming, images are returned as base64 (
b64_json) by default; withresponse_format: "url"the final image is returned as a URL, while partial images stay base64. - Without partial images the connection may be silent for a long time before the final image arrives, so set your client’s read timeout to a few minutes.
Common parameters
Notes
Related links
OpenAI image generation guide
Official usage guide, including streaming and editing
OpenAI Images API reference
Full parameters and event fields