Quick Overview
gpt-image-2 is an image generation and image editing model available through LaoZhang API. Use it when you need an OpenAI-compatible path that can cover both text-to-image and image-to-image workflows.
Price
gpt-image-2 is billed per request at $0.03/call.Online Test
Test the model online at yingtu.ai before integrating the API.
Which Endpoint Should You Use?
| Need | Recommended endpoint | Response shape |
|---|---|---|
| You already use Chat Completions and want minimal changes | /v1/chat/completions | Markdown image URL in choices[0].message.content |
| You only need text-to-image with the standard Images API shape | /v1/images/generations | data[0].b64_json by default, or data[0].url |
| You need multipart local image upload for image editing | /v1/images/edits | data[0].b64_json by default, or data[0].url |
| Your source image is already a CDN URL or base64 data URL | /v1/chat/completions | Markdown image URL |
Base Configuration
https://api.laozhang.ai/v1. Do not set the base URL to a model-level path.
Chat Completions Text-to-Image
This is the simplest integration path. Setmodel to gpt-image-2 and put the image request in messages.
choices[0].message.content:
Chat Completions Image-to-Image
Use/v1/chat/completions when your source image is available as a CDN URL or a base64 data URL. In this mode, messages[].content is an array that includes both the text instruction and the image input.
Use an Image URL
Use a base64 Data URL
Images Generations Text-to-Image
If your code already uses the OpenAI Images API shape, call/v1/images/generations.
The default response returns data[0].b64_json:
response_format when you want a URL:
Images Edits Image-to-Image
Use/v1/images/edits when your source image is a local file and multipart upload is the most convenient path.
The default response returns data[0].b64_json:
Parse Responses
Extract a Chat Completions Image URL
Save Images API b64_json
Read an Images API URL
Prompt Pattern for Image Editing
For image-to-image, tell the model what to preserve and what to change. A reliable pattern is:- Keep the product, background, and camera angle; change only a color or local decoration.
- Keep the card position and text; add only a border, label, or small icon.
- Avoid “generate a similar image”, which can encourage the model to redraw the whole image.
FAQ
Why is there no data[0].url in Chat Completions?
Why is there no data[0].url in Chat Completions?
/v1/chat/completions returns a chat completion shape. The image URL is inside the Markdown image link at choices[0].message.content. data[0].url belongs to Images API responses.Why does b64_json decoding fail?
Why does b64_json decoding fail?
Check whether the value includes a
data:image/png;base64, prefix. If it does, split on the first comma and decode only the second part.How much does it cost?
How much does it cost?
gpt-image-2 is billed per request at $0.03/call.Can I test it online first?
Can I test it online first?
Yes. Visit yingtu.ai to test prompts online, then move the confirmed prompt into your API call.